Page 1 of 1 1
Topic Options
#46504 - 2003-10-09 04:21 PM While loops problem with "IF EXIST function"
Peter Fry Offline
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
#46505 - 2003-10-09 04:25 PM Re: While loops problem with "IF EXIST function"
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
well,

this line

quote:
WHILE "IF EXIST ($FULLDEST)=1"
should be replaced by

code:
WHILE EXIST ($FULLDEST)

_________________________



Top
#46506 - 2003-10-09 04:33 PM Re: While loops problem with "IF EXIST function"
Peter Fry Offline
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
#46507 - 2003-10-09 04:38 PM Re: While loops problem with "IF EXIST function"
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
k,

build $FULLDEST AFTER you increase your counter, not before [Wink]
_________________________



Top
#46508 - 2003-10-09 04:40 PM Re: While loops problem with "IF EXIST function"
Peter Fry Offline
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
#46509 - 2003-10-09 04:41 PM Re: While loops problem with "IF EXIST function"
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And please don't use variables inside strings as it makes the code really hard to understand.
_________________________
There are two types of vessels, submarines and targets.

Top
#46510 - 2003-10-09 04:44 PM Re: While loops problem with "IF EXIST function"
Peter Fry Offline
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 Offline
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 Offline
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
#46513 - 2003-10-10 09:25 AM Re: While loops problem with "IF EXIST function"
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
they will alert if there is "syntax error"
thus they will make the making of mistakes lot harder.
obviously if you read manual or FAQ, you would know that the irc var is to suppress the output not going to console.

and if we go to deeper in faq you would even know that iRC is hungarian notated integer return code.

any more questions? [Wink]
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.128 seconds in which 0.02 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org