Hoping someone can help cause I've wasted ALOT of time on this.
I have a directory that downloads a number of reports. These each take the same format: CDR_yyyymmdd.csv
I want to be able to access the FIRST file in a directory that matchese that pattern(just CDR*.csv will do and first copy it to another directory and then rename it.
For the record another program comes along and processes the renamed file and then deletes it, so I can only process one file per sweep.
Thanks for any help.
move and rename FIRST file in directory
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
Here's a start for you... this also sorts them in File Name Order. If you don't need to sort, then remove the /ON from the DIR command. It will only move the first file, then get out. Otherwise, if you need to move more than one, you'll have to remove the Goto GetOut.
Code: Select all
For /F "Delims=" %%F In ('Dir /B/ON CDR_*.csv') Do (
Copy /v %%F \NewLoc\NewName.ext
If Exist \NewLoc\NewName.ext (
Erase %%F
Echo Move of File %%F was Successful!
) Else (
Echo Error on Moving file %%F!
)
Goto GetOut
)
:GetOut
Echo;
Echo Finished Moving file Job