K.C.Leblanc Posted November 28, 2007 Posted November 28, 2007 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.
SYNACK Posted November 28, 2007 Posted November 28, 2007 If its not that it might be the {} brackets around the loop contents, if the syntax is like C
SYNACK Posted November 28, 2007 Posted November 28, 2007 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.
webman Posted November 28, 2007 Posted November 28, 2007 AutoIt doesn't have that syntax. http://www.autoitscript.com/autoit3/docs/keywords/For.htm
K.C.Leblanc Posted November 28, 2007 Author Posted November 28, 2007 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.
webman Posted November 28, 2007 Posted November 28, 2007 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 :?
K.C.Leblanc Posted November 28, 2007 Author Posted November 28, 2007 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now