Help to copy file and rename source file

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
red_whiteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AnilKumarSharmaCommented:
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
red_whiteAuthor Commented:
Thanks

How can I add curent datum to source file after copy file to destination folder.
0
gcastillo31Commented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

gcastillo31Commented:

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

try it
0
Farhan KaziSystems EngineerCommented:
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
red_whiteAuthor Commented:
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
red_whiteAuthor Commented:
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
Farhan KaziSystems EngineerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
red_whiteAuthor Commented:
Hi Farhankazi

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

Regards
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.