Wednesday, February 9, 2011

[Trick] DOS Batch - Renaming file with current date

I got this assignment that requested me to create daily scheduler of which doing maintenance of files, like backup file to another directory and adding current date in the file's name.

So I try the most simple method I could think of: Windows Scheduler and A Batch File.

So here what I've got for the Batch file:
@echo off
set new_file_name=[source_file_name]%date:~4,10%
set new_file_name=%new_file_name:/=-%

copy "[source_path][source_file_name].ext" "[destination_path]%new_file_name%.ext"
After that I'll just have to create a Scheduler set to run that batch file on requested time-run.

There you go...! Have a try and please, give me some feedback of your own experiment result.

No comments: