Solved

MS DOS Move file

Posted on 2011-03-01
13
566 Views
Last Modified: 2012-05-11
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
Comment
Question by:ramziabk
  • 6
  • 5
  • 2
13 Comments
 
LVL 8

Expert Comment

by:Forefront_Data_Solutions
ID: 35007197
Are you trying to do this from within SQL Server, or just DOS commands?
0
 
LVL 1

Author Comment

by:ramziabk
ID: 35007274
dos command
0
 
LVL 8

Accepted Solution

by:
Forefront_Data_Solutions earned 500 total points
ID: 35007285
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
 
LVL 8

Expert Comment

by:Forefront_Data_Solutions
ID: 35007303
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
 
LVL 1

Author Comment

by:ramziabk
ID: 35015170
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
 
LVL 8

Expert Comment

by:Forefront_Data_Solutions
ID: 35016573
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 1

Author Comment

by:ramziabk
ID: 35016640
It is exactly  the same as you posted. I just copied and paste it.
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 35016679
==> ramziabk

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

ECHO %DATE%

~bp
0
 
LVL 8

Expert Comment

by:Forefront_Data_Solutions
ID: 35016704
It must be an environment setting.  Open a command prompt, type:

DATE/T

and paste it here.
0
 
LVL 1

Author Comment

by:ramziabk
ID: 35016837
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
 
LVL 1

Author Closing Comment

by:ramziabk
ID: 35016843
Date Format should be M/D/YY
0
 
LVL 8

Expert Comment

by:Forefront_Data_Solutions
ID: 35016887
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
 
LVL 52

Expert Comment

by:Bill Prew
ID: 35017309
Can you share what both these display from a command line:

ECHO %DATE%

DATE /T

~bp
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now