mrMotion
01-20-2004, 08:48 PM
Hello, I've got some problems with a while loop; It loops for ever. The loop is suposed to print the content of some files. Since the script don't know how many files there are, it checks if the next file exists or not inside of the loop. If the next file does not exist, it is going to stop:
//---------
int $counter = 1;
string $fileName = "example" + $counter + ".txt";
$exampleFileName[$counter] = ( `internalVar -userScriptDir` + $fileName );
int $fileExist = `filetest -f $exampleFileName[$counter]`;
while(0 < $fileExist)
{
$fileId=`fopen $exampleFileName[$counter] "r"`;
string $s;
$s=`fread $fileId $s`;
print( $s + "\n" );
fclose $fileId;
$counter = $counter + 1;
$fileName = "example" + $counter + ".txt";
$exampleFileName[$counter] = ( `internalVar -userScriptDir` + $fileName );
int $fileExist = `filetest -f $exampleFileName[$counter]`;
}
//---------
//---------
int $counter = 1;
string $fileName = "example" + $counter + ".txt";
$exampleFileName[$counter] = ( `internalVar -userScriptDir` + $fileName );
int $fileExist = `filetest -f $exampleFileName[$counter]`;
while(0 < $fileExist)
{
$fileId=`fopen $exampleFileName[$counter] "r"`;
string $s;
$s=`fread $fileId $s`;
print( $s + "\n" );
fclose $fileId;
$counter = $counter + 1;
$fileName = "example" + $counter + ".txt";
$exampleFileName[$counter] = ( `internalVar -userScriptDir` + $fileName );
int $fileExist = `filetest -f $exampleFileName[$counter]`;
}
//---------
