Hi Dos Gurus,
I need help to copy files to their relevant directories.
The following files reside in one directory say for example C:\Test\workdir
20090402_000010.csv
20081201_000042.csv
20090301_000081.csv
20090301_000024.csv
20090328_000012.csv
and so on...
The first part of filename is date and the second part holds reference to a directory name where it should be copied into.
i.e. 000010, 000042, 000081 etc.,
If the file name is 20090402_000010.csv then that file should be copied to a directory called C:\Test\000010\indir
and similarly if the filename is 20081201_000042.csv then this will have to go to C:\Test\000042\indir
and so on...
The other possible directories are
C:\Test\000012\indir
C:\Test\000081\indir
C:\Test\000024\indir
C:\Test\000030\indir etc.,
Please advise how do I write a program to copy the files.
Thanks for your valuable time and help.
Copy files to their relevant directory
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
You could try something like:
Code: Select all
For /F "Tokens=1,2,3* Delims=_." %%F In ('Dir /B \Test\WorkDir\*.csv') Do (
Echo Copying %%F CSV file to %%G
Copy /v %%F_%%G.%%H \Test\%%G\indir
)
-
- Posts: 4
- Joined: 01 Apr 2009 10:47