Jump to content

Recommended Posts

Posted

I've just managed to break a script I'm working on and I can't work out why.

 

#include 
Dim $aRecords
Dim $DirLoc
_FileReadToArray("list.txt",$aRecords)


For $x = 1 to $aRecords[0]

$DirLoc = "C:\Documents and Settings\" & $aRecords[$x]


If FileExists($DirLoc) Then
	DirRemove ($DirLoc ,1)


NEXT

 

The error is "Next" statement with no matching "For" statement.

Posted

Possibly as below

#include 
Dim $aRecords
Dim $DirLoc
_FileReadToArray("list.txt",$aRecords)


FOR $x = 1 to $aRecords[0]{
$DirLoc = "C:\Documents and Settings\" & $aRecords[$x]


If FileExists($DirLoc) Then
	DirRemove ($DirLoc ,1)
       }
NEXT

 

Otherwise I think it will only loop the first line.

Posted

Cheers webman, Endif sorts it. Or placing the line that starts DirRemove on the same line as the if.

 

I'm going to have to change it anyway. I'm getting errors if there are blank lines in my text file.

Posted

Cool :)

 

For the blank line problem, I would do.... in the loop, a Stringlen() check against $aRecords[$x]; and only do FileExists() if len is greater than 1? But saying that, the DirExists() function should catch any problematic directories :?

Posted

What's happening is if there is a blank line it trys to delete c:\documents and settings. Luckily Autoit has a fail safe.

 

At the moment I'm up to

#include 
Dim $aRecords
Dim $DirLoc
_FileReadToArray("list.txt",$aRecords)


For $x = 1 to $aRecords[0]


$DirLoc = "C:\Documents and Settings\" & $aRecords[$x]

If $aRecords[$x] = True then
	If FileExists($DirLoc) Then 
	DirRemove ($DirLoc ,1)
	EndIf
EndIf



Next

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...