path - Add Date/time/old location to file name Batch -


i have following code:

@echo off setlocal disabledelayedexpansion  set "src=c:\test" set "dst=c:\test2" set "search=test"  /r "%src%" %%f in (*%search%*) ( set "full=%%~ff" set "name=%%~nxf" setlocal enabledelayedexpansion copy "!full!" "%dst%\!name:%search%=test - %date:~0,2%-%date:~3,2%-%date:~6,4%__%time:~0,2%-%time:~3,2%-%time:~6,2%!" endlocal ) 

what code copy file 1 location , put on other location , change name , put date/time in filename.

where looking behind filename , time comes location of copyed file. this:

filename-10-03-2014-15:58:45-c:\test\test1\testfile.txt

so can see date time , old path in filename.

hope guys can help.

kind regards,

kaluh

@echo off setlocal disabledelayedexpansion  set "src=c:\sourcedir" set "dst=c:\destdir" set "search=jpg"  /r "%src%" %%f in (*%search%*) (  set "full=%%~ff"  set "name=%%~nxf"  setlocal enabledelayedexpansion  set "appendix=!full::=-!"  set "appendix=!appendix:\=_!"  echo copy "!full!" "%dst%\!name:%search%=test - %date:~0,2%-%date:~3,2%-%date:~6,4%__%time:~0,2%-%time:~3,2%-%time:~6,2%!-!appendix!"  endlocal )  goto :eof 

i changed search pattern, source , destination directories suit system.

you need nominate own substitute characters : , \ cannot appear in filename.

the required copy commands merely echoed testing purposes. after you've verified commands correct, change echo copy copy copy files.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -