Solved

MS DOS Move file

Posted on 2011-03-01
13
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
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 56

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 56

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

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!

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

626 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