Copying a file with a date.
Posted 09 June 2011 - 10:19 AM
I have a file being copied from one location to another, and then renamed. The name of the file in the source is "CT" plus the current date in the format MMDDYY. So, as an example, today's file would be called CT060911.txt and tomorrow would be CT061011.txt.
This file is created everyday and I need to pull a copy of it everyday and put it in a new directory.
I've created a batch file that copies the file, puts it in the appropriate directory, and then renames it to a new name, except for the part about automatically updating for the date.
such as -
copy "I:\CT060911.txt" "C:\Import"
rename "C:\Import\CT060911.txt" NewName.txt
My hope is to call the batch file from a scheduled task, and have the batch file automatically look for the file with the current date in the name. Most of the examples I've seen online seem to be concerned with renaming the file with the current date, instead of finding a file with the current date, and I can't seem to get things to work the other way around. Any help would be greatly appreciated. Thanks!
Posted 09 June 2011 - 01:01 PM
The problem is usually with regional settings/international standards, but if you only use on a given system or on more systems with the same country settings, it is quite easy to manage it..
Posted 09 June 2011 - 02:00 PM
for /f "delims= usebackq" %%i in (`date.exe +%%m%%d%%y`) do (set currname=%%i) copy "i:\CT%currname%.txt" "c:\import"
Be sure to set the right path to date.exe in the batch or else it might try to call the builtin windows date.
This post has been edited by allen2: 09 June 2011 - 02:01 PM
- ← How to pass/convert "http%3a%2f%2f" in batch variable
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Can someone convert this batch file into a VBS? →