Hi everyone, i'm very new to batch files and i'm looking for some help.
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!
Page 1 of 1
Copying a file with a date.
#2
Posted 09 June 2011 - 01:01 PM
Well, it depends on the OS you are running, if anyhting like 2K and later you can use the %DATE% variable allright.
Some reference:
http://www.robvander...om/datetime.php
http://www.robvander...imentbasics.php
http://www.robvander.../datetiment.php
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..
jaclaz
Some reference:
http://www.robvander...om/datetime.php
http://www.robvander...imentbasics.php
http://www.robvander.../datetiment.php
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..
jaclaz
#3
Posted 09 June 2011 - 02:00 PM
To avoid the problem raised by jaclaz you could use the unix tool date.exe like this:
Be sure to set the right path to date.exe in the batch or else it might try to call the builtin windows date.
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
#4
Posted 15 June 2011 - 09:31 AM
I ended up getting the Date command to work.
Thanks for the links and the suggestions and getting me pointed in the right direction.
Thanks for the links and the suggestions and getting me pointed in the right direction.
- ← 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? →
Share this topic:
Page 1 of 1



Help
Back to top










