Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 581
  • Last Modified:

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
0
ramziabk
Asked:
ramziabk
  • 6
  • 5
  • 2
1 Solution
 
Forefront_Data_SolutionsCommented:
Are you trying to do this from within SQL Server, or just DOS commands?
0
 
ramziabkAuthor Commented:
dos command
0
 
Forefront_Data_SolutionsCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now