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 ,

Copy a file called chauffeur.accdb to a file called chauffeur1.accdb
 
The next time the bat file is run copy the file to chauffeur2.accdb . the next time to chauffeur3.accdb etc
 
also to throw into the mix delete the oldest version (retaining 5 copies on disk)
 
Many thanks
 
Thanks David

Works well

Regards

ianWho's David ? ?

Did Bill PM you ? ?IAN, please post "David"'s code. This is not a private help service. (What is his USERNAME?)


Addressing the requirements expressed in the post that opened the thread, one way of doing this, it seems to me is:

Each time the script is run:

check if chauffeur1.accdb exists,
if it does,
check if chauffeur2.accdb exists
if it does not,
copy (or rename) chauffeur.accdb to chauffeur1.accdb
(repeat for 2 to 6)

If the new filename was chauffeur5.accdb (or less)
exit
If the new filename was chauffeur6.accdb
delete chauffeur1.accdb
for n=2,3,4,5,6: rename file chauffeur(n).accdb as chauffeur(n-1).accdb
exit

Tomorrow, the code!
Quote from: Salmon Trout on November 04, 2011, 06:00:26 PM

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


Discussion

No Comment Found