[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Help to copy file and rename source file

Posted on 2010-03-28
10
Medium Priority
?
330 Views
Last Modified: 2012-05-09
Hi All

I have to copy file from c:\ to d:\ and after copy rename source file (or stamp with current date)
OS: Windows XP/Vista/Windows 7/Windows 2003

Thanks
0
Comment
Question by:red_white
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 9

Assisted Solution

by:AnilKumarSharma
AnilKumarSharma earned 200 total points
ID: 28947191
copy these two lines in a notepad and save it as batch file like "mytask.bat". Replace the sourcedir, sourcefile.ext adn newsourcename.ext with the one you have and required.

xcopy c:\sourcedir\sourcefile.ext d:\destinationdir\
ren c:\sourcedir\sourcefile.ext c:\sourcedir\newsourcename.ext
0
 

Author Comment

by:red_white
ID: 28948760
Thanks

How can I add curent datum to source file after copy file to destination folder.
0
 
LVL 1

Expert Comment

by:gcastillo31
ID: 28950211
hola este script te permite pasar como parametro una fecha de esta manera puedes renombrar los ficheros de origen.
try it

http://www.robvanderwoude.com/datetimentexamples.php

saludos


 
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:gcastillo31
ID: 28950231

hi this script as a parameter lets you pass a date in this way you can rename the source files.

try it
0
 
LVL 26

Expert Comment

by:Farhan Kazi
ID: 28951013
Check following batch script if this works for you!

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=*" %%I IN ('DIR C:\DATA\*.* /B') DO (
	SET MM=%DATE:~4,2%
	SET DD=%DATE:~7,2%
	SET YYYY=%DATE:~10,4%
	ECHO Coping %%I
	COPY "%%I" "D:\DATA\%%~nI_!MM!_!DD!_!YYYY!%%~xI">NUL)

Open in new window

0
 

Author Comment

by:red_white
ID: 28951076
I found way to rename file with current date
ren *.log %date:~-10,2%%date:~-7,2%%date:~-2,2%.log
but will be better to add date to source file.

Regards to all
0
 

Author Comment

by:red_white
ID: 28952576
Hi Farhankazi

This batch scrip add date to  name.file  on destination. I need script after copy file from  c:\ to d:\ to add date to file on c:\

regards
0
 
LVL 26

Accepted Solution

by:
Farhan Kazi earned 800 total points
ID: 28954745
Try this:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
XCOPY /E C:\Data\*.* D:\Data\
FOR /R C:\DATA %%I IN (*.*) DO (
        SET MM=%DATE:~4,2%
        SET DD=%DATE:~7,2%
        SET YYYY=%DATE:~10,4%
        RENAME "%%I" "%%~nI_!MM!_!DD!_!YYYY!%%~xI")

Open in new window

0
 

Author Comment

by:red_white
ID: 28955838
Hi Farhankazi

Thanks, that was what I need.
Any site to learn more about batch script?

Regards
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

607 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