| 1. |
Solve : BAT file to copy a file to a different name every time? |
|
Answer» I would like to be able to do the following in a bat file , if possible , Tomorrow, the code! Code: [SELECT]echo off set maxnum=5 set filenum=1 :loop if exist chauffeur%filenum%.accdb set /a filenum +=1 & goto loop ren chauffeur.accdb chauffeur%filenum%.accdb if %filenum% leq %maxnum% goto end set /a oldnum=1 set /a stopnum=%maxnum%+1 :renum set /a newnum=%oldnum%-1 ren chauffeur%oldnum%.accdb chauffeur%newnum%.accdb set /a oldnum+=1 if %oldnum% leq %stopnum% goto renum del chauffeur0.accdb :endHi Salmon Trout Your code works well but what it doesn't do is retain the original chauffeu.accdb therefore I would have to change my desktop SHORTCUT everytime I ran my DB best regards Ian Quote from: ian1956 on November 05, 2011, 07:28:24 AM what it doesn't do is retain the original chauffeu.accdb therefore I would have to change my desktop shortcut everytime I ran my DB Answered via PM but we might as well let the whole world see... Code: [Select]echo off set maxnum=5 set filenum=1 :loop if exist chauffeur%filenum%.accdb set /a filenum +=1 & goto loop REM uncomment the next line if you want to RENAME chauffeur.accdb to the next available number (1-5) REM ren chauffeur.accdb chauffeur%filenum%.accdb > nul REM uncomment the next line if you want to COPY chauffeur.accdb to the next available number (1-5) REM copy chauffeur.accdb chauffeur%filenum%.accdb > nul if %filenum% leq %maxnum% goto end set /a oldnum=1 set /a stopnum=%maxnum%+1 :renum set /a newnum=%oldnum%-1 ren chauffeur%oldnum%.accdb chauffeur%newnum%.accdb set /a oldnum+=1 if %oldnum% leq %stopnum% goto renum del chauffeur0.accdb :end Note: chauffeur0.accdb is the oldest file that has dropped off the bottom of the list; instead of simply deleting it you could move it somewhere else to archive it if you wanted to. Hi Salmon Trout Much appreciated works well Best regards Ian |
|