Jump to content

Recommended Posts

Posted

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!


Posted

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.robvanderwoude.com/datetime.php

http://www.robvanderwoude.com/datetimentbasics.php

http://www.robvanderwoude.com/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

Posted (edited)

To avoid the problem raised by jaclaz you could use the unix tool date.exe like this:


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.

Edited by allen2
Posted

I ended up getting the Date command to work.

Thanks for the links and the suggestions and getting me pointed in the right direction.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...