#46504 - 2003-10-09 04:21 PM
While loops problem with "IF EXIST function"
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
code: $SOURCE = c:\temp $DEST = c:\test $FULLFILENAME = test.doc $NAME = test $EXTENSION = doc $FULLSOURCE = "$SOURCE\$FULLFILENAME" $RENAMED = "$SOURCE\$NAME-WD.$EXTENSION" $FULLDEST = "$DEST\$FULLFILENAME" $COUNTER = 0 ? "$FULLDEST" ? " " :CHECK WHILE "IF EXIST ($FULLDEST)=1" ? "$FULLDEST Exists" $FULLDEST = "$DEST\$NAME$COUNTER.$EXTENSION" $COUNTER = $COUNTER + 1 $NEWNAME = "$NAME$COUNTER.$EXTENSION" SHELL "%COMSPEC% /c rename $FULLSOURCE $NEWNAME" $FULLSOURCE = "$SOURCE\$NEWNAME" ? "$FULLDEST" ? " " LOOP basically i want to check if a file is not in the location before i use a copy command, and if it is rename the file so it can copy with out overrighting the file i'm using the GUI copy UDF all i need to do is check if the file exists if it does rename the orginal file to $name$counter.$extension and then check if the file exists again and carry on this renameing untill the file does not exist all it does at the moment is loop around what am i doing wrong?
Top
#46506 - 2003-10-09 04:33 PM
Re: While loops problem with "IF EXIST function"
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
thx the loop stops but now i have this problem if in c:\temp i have a file called test.doc and in c:\test i have 3 files called test.doc test1.doc test2.doc as far as i read the script it should check test.doc is there if so rename to test1.doc check if that is there etc etc but it doesn't, after the loop i have the copy command and it fires off as soon as it's renamed the file once and trys to overwrite the file any ideas?
Top
#46508 - 2003-10-09 04:40 PM
Re: While loops problem with "IF EXIST function"
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
i can't believe i missed that!, thx Jochen you're a star!
Top
#46510 - 2003-10-09 04:44 PM
Re: While loops problem with "IF EXIST function"
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
just so i know how would you have wrote it sealeopard, so i know the correct way in the future (i'm still learning lots)
Top
#46511 - 2003-10-09 04:51 PM
Re: While loops problem with "IF EXIST function"
Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
break off
dim $iRC
$iRC =setoption ('Explicit' ,'on' )
$iRC =setoption ('NoVarsInStrings' ,'on' )
dim $sSource , $sDest , $sName , $sExtension , $iCounter
dim $sFullSource , $sFullFileName , $sFullDest , $sRenamed
$sSource = 'c:\temp'
$sDest = 'c:\test'
$sFullFileName = 'test.doc'
$sName = 'test'
$sExtension = 'doc'
$sFullSource = $sSource +'\' +sFullFileName
$sRenamed = $sSource +'\' +$sName +'-WD.' +$sExtension
$sFullDest = $sDest +'\' +$sFullFileName
$iCounter = 0
_________________________
There are two types of vessels, submarines and targets.
Top
#46512 - 2003-10-10 08:52 AM
Re: While loops problem with "IF EXIST function"
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
Thanks Sealleopard i understand allt he dim 's and the way you are adding the strings together but why do you need to do the $iRC options etc? thanks again
Top
Moderator: Jochen , Allen , Radimus , Glenn Barnas , ShaneEP , Ruud van Velsen , Arend_ , Mart
0 registered
and 2220 anonymous users online.