Link to home
Start Free TrialLog in
Avatar of cawasaki
cawasaki

asked on

batch command to copy a file with specific date

Hi,

i need a dos command to schedule a copy of the file who change the name every day, for exemple:

File1_28-11-10

File1_29-11-10

File1_30-11-10

I need a good variable to use a copy command.

Thanks
Avatar of moon_blue69
moon_blue69

HI

You can use the forfiles command to achieve this task where you can search for a file how old it is and delete it. You might need to download the command and paste it in system32

ftp://ftp.microsoft.com/ResKit/y2kfix/x86/

Avatar of cawasaki

ASKER

how can i use this to cpoy a file with specific date in the file name?
Check your system date format with DATE-command.

Assuming your system date format is dd-mm-yyyy...
Set File_Prefix=File1_

Set mm=%DATE:~3,2%  
Set dd=%DATE:~0,2%
Set yy=%DATE:~8,2%

REM Variable to adress file
set File_name=%File_Prefix%%dd%-%mm%-%yy%

Open in new window

With COPY-command...

Schedule this batch script with standard Windows Task Scheduler...
Set File_Prefix=File1_

Set mm=%DATE:~3,2%  
Set dd=%DATE:~0,2%
Set yy=%DATE:~8,2%

REM Variable to adress file
set File_name=%File_Prefix%%dd%-%mm%-%yy%
 
Copy C:\DIR1\%File_name% C:\DIR2

Open in new window

Thommy

not work

What's your system date format???

The paramters for the following commands must be adapted to your special system date format.

Open a DOS box and Type in "DATE" to check for your date format.
date.bmp
Sorry, have forgotten the commands which must be adapted to your date format:

Set mm=%DATE:~3,2%  
Set dd=%DATE:~0,2%
Set yy=%DATE:~8,2%

If this is not your problem, please tell me more detailled what goes wrong!!!
hi,

La date du jour est : 30/11/2010
Entrez la nouvelle date : (jj-mm-aa)

Your script map the current date to the file to copy, but if i need to copy a file with old day, its not work...

for exemple if i need to copy to day a file named "File1_28-11-10", its not work because your script use a variable for today and try to copy this file: "File1_30-11-10"
replace the fileName and destinationFolder and execute the script

this is vbscript

save the file as .vbs and execute it as

cscript filename.vbs
fileName = "test_"
destinationFolder = "c:\test"
datePattern = Year(Date) &  "-" & Month(Date) & "-" & Day(Date)
datePattern = Right("0" & Day(date),2) & "-" & Right("0" & Month(date),2) & "-" & Right(Year(date),2)
fileName = fileName & datePattern
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile fileName, destinationFolder

Open in new window

What do you want to do in detail???

Do you want to copy files with current date or with old date???
itkamaraj

Not work
what error you are getting ?

please give the correct file name and where you want to move the file ?
i want to copy the file, not move him.

the file name is test_29-11-10.txt. i need to copy it to c:\test.

the file name can change, for exemple, to day the file name is test_30-11-10.txt

Tomorow, the file name must be test_01-12-10.txt.

Thanks
try this
fileName = "test_"
destinationFolder = "c:\test"
datePattern = Year(Date) &  "-" & Month(Date) & "-" & Day(Date)
datePattern = Right("0" & Day(date),2) & "-" & Right("0" & Month(date),2) & "-" & Right(Year(date),2)
fileName = fileName & datePattern
fileName = fileName & ".txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.copyFile fileName, destinationFolder

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Schedule this batch with Windows Task Scheduler as a daily task, so that the file is copied to destination directory daily...
Set File_Prefix=test_
Set File_Ext=.txt
Set Dest_Dir=c:\test

Set mm=%DATE:~3,2%  
Set dd=%DATE:~0,2%
Set yy=%DATE:~8,2%

REM Variable to adress file
set File_name=%File_Prefix%%dd%-%mm%-%yy%%File_Ext%
 
Copy %File_name% %Dest_Dir%

Open in new window