MSFN Forum: Copying a file with a date. - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Copying a file with a date. Rate Topic: -----

#1 User is offline   dichronic 

  • Group: Members
  • Posts: 2
  • Joined: 09-June 11
  • OS:XP Pro x86
  • Country: Country Flag

Posted 09 June 2011 - 10:19 AM

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!


#2 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,456
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

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

#3 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,737
  • Joined: 13-January 06

Posted 09 June 2011 - 02:00 PM

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.

This post has been edited by allen2: 09 June 2011 - 02:01 PM


#4 User is offline   dichronic 

  • Group: Members
  • Posts: 2
  • Joined: 09-June 11
  • OS:XP Pro x86
  • Country: Country Flag

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.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy