Solved

MS DOS Move file

Posted on 2011-03-01
13
573 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
LVL 1

Author Comment

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

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 53

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

839 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