windows - Copying multiple files and adding date to the name bat -


i have make .bat file this:

copies o:\siirto files name starts "ls". c:\siirto. , name of output same in source. add current date end of file name.

i tried following test , didnt work of course :d. propably explains better im trying explanation above.

echo off xcopy o:\siirto\ls* c:\siirto\ls%date.txt pause 

of course not working. possible 1 .bat file. or have ls.txt-files own .bat-files or lines.

like 1 ls1.txt, ls2.txt ls3.txt

echo off xcopy o:\siirto\ls1.txt c:\siirto\ls1%date pause 

i have no idea how %date should add code , need else code also?

im still on child shoes in programming...

thanks

you need combine iteration on files for command , %date% environment variable. read help for, paying attention %~ expansion syntax, , try following code.

for %%a in (o:\siirto\ls*) (    echo copy "%%a" "c:\siirto\%%~na-%date%%%~xa" ) 

after careful testing, remove echo command.


you might generalize bit code, moving configurable information out of loop

set src=o:\siirto\ls* set dest=c:\siirto %%a in (%src%) (   copy "%%a" "%dest%\%%~na-%date%%%~xa" ) 

and, in case %date% command returns invalid characters, read accepted answer question batch script date variable , change variable 1 contains current date appropiate format.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -