MS DOS Move file

I have to move a file using MS DOS move command. I need also to append the file name with system date so that the next day, the file won't be overwritten.

Example:
The file name is Prices.xls located on C:\
I want to move it to location D:\ and rename the file to prices_01032011.xls.

How to acheive that?
Thanks
LVL 1
ramziabkAsked:
Who is Participating?
 
Forefront_Data_SolutionsConnect With a Mentor Commented:
Using Notepad or Wordpad, create a new file.  Copy/paste the following:


 
REM The following statements just add a date/time stamp to the Log file
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)

FOR /F "TOKENS=1* DELIMS= " %%A IN ('TIME/T') DO SET CTIME=%%B
For /f "tokens=1-4 delims=: " %%a in ('time /t') do (set time=%%a%%b%%c) 

REM Put the correct path for the input file and the log file locations

SET OUTPUTFILE=D:\prices_%date%.xls

MOVE c:\Prices.xls %OUTPUTFILE%

Open in new window


If you also want a timestamp, change the following:

SET OUTPUTFILE=D:\prices_%date%%time%.xls
0
 
Forefront_Data_SolutionsCommented:
Are you trying to do this from within SQL Server, or just DOS commands?
0
 
ramziabkAuthor Commented:
dos command
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Forefront_Data_SolutionsCommented:
Oh yeah, save the file with a ".bat" extension, such as "movefile.bat".  You can then doubleclick to execute it, or you can use the scheduler to automatically run it at a certain time.
0
 
ramziabkAuthor Commented:
Thanks

The date is now showing but only as MONTHYEAR? THE days is not showing? How to enable the day to show?

Thanks again
0
 
Forefront_Data_SolutionsCommented:
Did you copy the code exactly as above?  Did you change any of it?  The above code works for me.  Please post your code so that I can look at it.
0
 
ramziabkAuthor Commented:
It is exactly  the same as you posted. I just copied and paste it.
0
 
Bill PrewCommented:
==> ramziabk

Can you do the following command at a DOS command prompt, and paste up exactly what is displayed.

ECHO %DATE%

~bp
0
 
Forefront_Data_SolutionsCommented:
It must be an environment setting.  Open a command prompt, type:

DATE/T

and paste it here.
0
 
ramziabkAuthor Commented:
For your statement to work, the date format in the regional setting should me M/D/YY. My date format was dd/mm/yyyy.

I changed the format and not it is working.
Thank you
0
 
ramziabkAuthor Commented:
Date Format should be M/D/YY
0
 
Forefront_Data_SolutionsCommented:
The other option would be to slightly change the code in the third line
From:
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)

To:
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%b%%a%%c)

REM The following statements just add a date/time stamp to the Log file
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%b%%a%%c)

FOR /F "TOKENS=1* DELIMS= " %%A IN ('TIME/T') DO SET CTIME=%%B
For /f "tokens=1-4 delims=: " %%a in ('time /t') do (set time=%%a%%b%%c) 

REM Put the correct path for the input file and the log file locations

SET OUTPUTFILE=D:\prices_%date%.xls

MOVE c:\Prices.xls %OUTPUTFILE%

Open in new window

0
 
Bill PrewCommented:
Can you share what both these display from a command line:

ECHO %DATE%

DATE /T

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.