home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

batch file on win xp

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2161
Discussions: 200,972, Posts: 2,379,766, Members: 246,336
Old September 24th, 2003, 10:47 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Sep 2003
Posts: 4
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 : September 24th, 2003 at 10:50 AM.
nnichols is offline   Reply With Quote
Old September 24th, 2003, 11:09 AM     #2 (permalink)
Retired mostly.
 
Join Date: Oct 2001
Location: Finland
Posts: 5,144
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 September 24th, 2003, 11:16 AM     #3 (permalink)
Junior Member
 
Join Date: Sep 2003
Posts: 4
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 September 24th, 2003, 11:24 AM     #4 (permalink)
Retired mostly.
 
Join Date: Oct 2001
Location: Finland
Posts: 5,144
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 September 24th, 2003, 11:36 AM     #5 (permalink)
Junior Member
 
Join Date: Sep 2003
Posts: 4
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 September 24th, 2003, 11:45 AM     #6 (permalink)
Junior Member
 
Join Date: Sep 2003
Posts: 4
I feel such a pratt.

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

nnichols is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3054)
The disrespect of Obama by Russian .. (48)
Delete an OS (16)
Breaking: San Diego ACORN Document .. (10)
Nvidia GTX 260 problem (8)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
windows vista security holes (17)
Regular Build (11)
windows 7 problem (7)
Internet Lost (5)
Point and Shoot Camera Suggestions. (6)
Print spooler problem (16)
Recent Discussions
Delete an OS (16)
Multiple Restarts Required at Boot (4)
cell phone won't work (0)
Nvidia GTX 260 problem (8)
Is the PSU I received dead? (15)
Can't open Word (12)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (37)
Steam ID's, Gamertags etc... (4)
Games, Cables, PCI cards, and more fo.. (6)
Dept. of HS: NSA 'Helped' Develop Vis.. (17)
Linksys WMP54GS wireless card problem.. (5)
windows vista security holes (17)
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)
Browsers wont load websites (3)
help me pls laptop just stopped worki.. (0)
Open With ..... Win7 (3)
Laptop with wireless problem. (12)
Internet Lost (5)
virus blocking exe. files (1)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Modern Warfare 2: Who Bought It? (65)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)


All times are GMT -4. The time now is 10:15 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28