arrays - Windows Batch Static List Rename-Move -


i relatively new batch scripts , trying create windows batch file renames static array values in 1 group against static array values in - moving folder. this:

setlocal enabledelayedexpansion  set currentdate=%date:~-4,4%%date:~-10,2%%date:~-7,2% set frompath=c:\ set topath=c:\temp\      set filelist=(temp1.txt temp2.txt temp3.txt) set tolist=(name1 name2 name3) 

i'm looking @ style of array looks easier user i'm giving to add list.

alone (without tolist) filelist works fine:

for %%i in %filelist% (     if exist %frompath%%%i        ren %frompath%%%i %%~ni_%currentdate%%%~xi &        move %frompath%%%~ni_%currentdate%%%~xi %topath% ) 

but not renaming tolist in same order list in tolist.

i tried code counter index (tried other variants of below aswell) no luck:

for /l %%i in (0,1,10) (   if exist %frompath%%filelist[%%i]%     ren %frompath%%%i %%~ni_%currentdate%%%~xi &      move %frompath%%%~ni_%currentdate%%%~xi %topath% ) 

is possible? if not, i'm open other suggestion above.

thanks in advance!

try this:

@echo off setlocal enabledelayedexpansion  set currentdate=%date:~-4,4%%date:~-10,2%%date:~-7,2% set frompath=c:\ set topath=c:\temp\      set filelist=(temp1.txt temp2.txt temp3.txt) set tolist=(name1 name2 name3)  rem separate tolist elements array set i=0 %%a in %tolist% (    set /a i+=1    set "tolist[!i!]=%%a" )  set i=0 %%f in %filelist% (    set /a i+=1    if exist %frompath%%%f (       ren %frompath%%%f %%~nf_%currentdate%%%~xf       %%i in (!i!) move %frompath%%%~nf_%currentdate%%%~xf %topath%!tolist[%%i]!    ) ) 

for further information array management in batch files, see: arrays, linked lists , other data structures in cmd.exe (batch) script


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -