»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 09-24-2003, 07:47 AM   #1 (permalink)
Registered User
 
Join Date: Sep 2003
Posts: 4
nnichols is on a distinguished road
batch file on win xp

Hi there,

Currently, I have a batch file for running a simple backup. The backup directory is set using the name of the directory being backed up plus the current date -

set dd=%date:~0,2%
set mm=%date:~3,2%
set yyyy=%date:~6,4%

set backupdir=c:\tempBAK%yyyy%%mm%%dd%

I need to modify the script so it checks to see if the directory already exists, and if so, it should append "-1" to the backupdir.

It then needs to check again to see if this new backupdir already exists, if so it should change the appended "-1" to "-2", and so on.

I have tried a few things but not making any real progress, and would very much appreciate any help anyone can give.

TIA

nick


Last edited by nnichols; 09-24-2003 at 07:50 AM.
nnichols is offline   Reply With Quote
Old 09-24-2003, 08:09 AM   #2 (permalink)
Registered User
 
muno's Avatar
 
Join Date: Oct 2001
Location: Finland
Posts: 3,838
muno is on a distinguished road
Send a message via Yahoo to muno
I can't test it, but I suppose it should work like this.

backup.bat
set dd=%date:~0,2%
set mm=%date:~3,2%
set yyyy=%date:~6,4%

set backupdir=c:\tempBAK%yyyy%%mm%%dd%

if exist %backupdir% (set backupdir=c:\tempBAK%yyyy%%mm%%dd%-1) else <here whatever it normally does>

now I don't know if that works like the way you want it to, but that should give you a good start
-M
muno is offline   Reply With Quote
Old 09-24-2003, 08:16 AM   #3 (permalink)
Registered User
 
Join Date: Sep 2003
Posts: 4
nnichols is on a distinguished road
Cheers,

I've already got that much, it's the next bit I'm struggling with.

Instead of appending "-1" it needs to be appending "-%i%" where "i" is an incremented number. That way I can check to see if it exists, if so grab the next value for "i" and try again until it does not exist, at which point the script can continue.

Thanks for your thoughts anyway

Nick
nnichols is offline   Reply With Quote
Old 09-24-2003, 08:24 AM   #4 (permalink)
Registered User
 
muno's Avatar
 
Join Date: Oct 2001
Location: Finland
Posts: 3,838
muno is on a distinguished road
Send a message via Yahoo to muno
Uh, I don't know if that can be done with normal dos commands
I'm sure with vbs it would be a 2minute job

See 'help if' in command prompt for insight on if.
-M
muno is offline   Reply With Quote
Old 09-24-2003, 08:36 AM   #5 (permalink)
Registered User
 
Join Date: Sep 2003
Posts: 4
nnichols is on a distinguished road
OK. I've now got this far, but my increment of "%i%" is not working -
Code:
@echo off

REM setup backup directory name

set dd=%date:~0,2%
set mm=%date:~3,2%
set yyyy=%date:~6,4%
set backupdir=c:\tempBAK%yyyy%%mm%%dd%
set backupdir1=%backupdir%
set i=0

REM check to see if directory already exists
:checkdir
if not exist %backupdir1% goto continue

set a/ i=%i% + 1
echo i: %i%
set backupdir1=%backupdir%-%i%
goto checkdir


:continue
echo Backup directory: %backupdir1%
Any thoughts as to the problem with "i" not being incremented?
nnichols is offline   Reply With Quote
Old 09-24-2003, 08:45 AM   #6 (permalink)
Registered User
 
Join Date: Sep 2003
Posts: 4
nnichols is on a distinguished road
I feel such a pratt.

Simple typo - "a/" should have been "/a".

nnichols is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 06:19 AM.