oshaker Posted October 5, 2009 Share Posted October 5, 2009 $FolderList = _FileListToArray($PathToBuild, "*", 2) For $d = 1 To $FolderList[0] DirRemove($PathToBuild & "\" & $FolderList[$d], 1) Next Compiler is complaining about this line: For $d = 1 To $FolderList[0] Error: Subscript used with non-Array variable I have to use UBound($FolderList) Any clue for this problem? Link to comment Share on other sites More sharing options...
99ojo Posted October 5, 2009 Share Posted October 5, 2009 $FolderList = _FileListToArray($PathToBuild, "*", 2) For $d = 1 To $FolderList[0] DirRemove($PathToBuild & "\" & $FolderList[$d], 1) Next Compiler is complaining about this line: For $d = 1 To $FolderList[0] Error: Subscript used with non-Array variable I have to use UBound($FolderList) Any clue for this problem? Hi, it looks l ike $FolderList isn't an array. So include array.au3 and just add a few lines for debugging: $FolderList = _FileListToArray($PathToBuild, "*", 2) If IsArray ($FolderList) Then _ArrayDisplay ($FolderList) Else Msgbox (0,"", $FolderList) ; see Return Values for _FileListToArray in Helpfile for debugging EndIf ;-)) Stefan Link to comment Share on other sites More sharing options...
oshaker Posted October 5, 2009 Author Share Posted October 5, 2009 _FileListToArray $FolderList = _FileListToArray($PathToBuild, "*", 2) For $d = 1 To UBound($FolderList) If @error = 0 Then DirRemove($PathToBuild & "\" & $FolderList[$d], 1) EndIf Next Compiler is complaining about For $d = 1 To UBound($FolderList) and gives the error Subscript used with non-Array variable Link to comment Share on other sites More sharing options...
oshaker Posted October 5, 2009 Author Share Posted October 5, 2009 (edited) including array.au3 doesn't work.. here is the compelte code: expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.0.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ; Script Start - Add your code below here #NoTrayIcon AutoItSetOption("MustDeclareVars", 1) #include <String.au3> #Include <Array.au3> #include <File.au3> ; Define Variables Dim $FileHandle, _ $LinesCount, _ $CoursePath, $PathToBuild, $FolderList, _ $NumberOfCourses, _ $i, $n, $c, $d, _ $FileToRead = "Course_Paths.txt" ; Get file handle $FileHandle = FileOpen($FileToRead, 0) ; Exit if error If @error <> -1 Then ; Count lines in file $LinesCount = _FileCountLines($FileToRead) ; Exit if count = 0 or error If $LinesCount = 0 Or @error = 1 Then Exit For $i = 1 To $LinesCount $CoursePath = FileReadLine($FileHandle, $i) If StringInStr($CoursePath, "'", 2) = 0 Then $CoursePath = StringSplit($CoursePath, "\") $NumberOfCourses = $CoursePath[$CoursePath[0]] ;MsgBox(0, "", $NumberOfCourses) For $n = 1 To $NumberOfCourses For $c = 1 To $CoursePath[0] - 2 $PathToBuild = $PathToBuild & $CoursePath[$c] If $c <> $CoursePath[0] - 2 Then $PathToBuild = $PathToBuild & "\" EndIf Next If $n < 10 Then $PathToBuild = $PathToBuild & "0" & $n Else $PathToBuild = $PathToBuild & $n EndIf $PathToBuild = $PathToBuild & "\" & $CoursePath[$CoursePath[0]-1] & "\" ;MsgBox(0, "", $PathToBuild) ;FileDelete($PathToBuild) $FolderList = _FileListToArray($PathToBuild, "*", 2) MsgBox(0, "", $FolderList) For $d = 1 To $FolderList[0] If @error = 0 Then MsgBox(0, "", $FolderList[$d]) MsgBox(0, "", UBound($FolderList)) DirRemove($PathToBuild & "\" & $FolderList[$d], 1) EndIf Next $PathToBuild = "" Next EndIf Next FileClose($FileHandle) EndIf Edited October 5, 2009 by oshaker Link to comment Share on other sites More sharing options...
99ojo Posted October 5, 2009 Share Posted October 5, 2009 including array.au3 doesn't work.. here is the compelte code: expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.0.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ; Script Start - Add your code below here #NoTrayIcon AutoItSetOption("MustDeclareVars", 1) #include <String.au3> #Include <Array.au3> #include <File.au3> ; Define Variables Dim $FileHandle, _ $LinesCount, _ $CoursePath, $PathToBuild, $FolderList, _ $NumberOfCourses, _ $i, $n, $c, $d, _ $FileToRead = "Course_Paths.txt" ; Get file handle $FileHandle = FileOpen($FileToRead, 0) ; Exit if error If @error <> -1 Then ; Count lines in file $LinesCount = _FileCountLines($FileToRead) ; Exit if count = 0 or error If $LinesCount = 0 Or @error = 1 Then Exit For $i = 1 To $LinesCount $CoursePath = FileReadLine($FileHandle, $i) If StringInStr($CoursePath, "'", 2) = 0 Then $CoursePath = StringSplit($CoursePath, "\") $NumberOfCourses = $CoursePath[$CoursePath[0]] ;MsgBox(0, "", $NumberOfCourses) For $n = 1 To $NumberOfCourses For $c = 1 To $CoursePath[0] - 2 $PathToBuild = $PathToBuild & $CoursePath[$c] If $c <> $CoursePath[0] - 2 Then $PathToBuild = $PathToBuild & "\" EndIf Next If $n < 10 Then $PathToBuild = $PathToBuild & "0" & $n Else $PathToBuild = $PathToBuild & $n EndIf $PathToBuild = $PathToBuild & "\" & $CoursePath[$CoursePath[0]-1] & "\" ;MsgBox(0, "", $PathToBuild) ;FileDelete($PathToBuild) $FolderList = _FileListToArray($PathToBuild, "*", 2) MsgBox(0, "", $FolderList) For $d = 1 To $FolderList[0] If @error = 0 Then MsgBox(0, "", $FolderList[$d]) MsgBox(0, "", UBound($FolderList)) DirRemove($PathToBuild & "\" & $FolderList[$d], 1) EndIf Next $PathToBuild = "" Next EndIf Next FileClose($FileHandle) EndIf Hi, you should add array.au3 for the _arraydisplay ($FolderList). 1) What is your output from _ArrayDisplay ($FolderList)? Is it an array or not? 2) If not, what is the output from MsgBox (0,"",@error) I did a debug mistake. You should add this lines, straight after your $FolderList = _FileListToArray statement and post result: $FolderList = _FileListToArray($PathToBuild, "*", 2); this is still in your code, add the next as written Msgbox (0,"", @error) ; please post error code or look in helpfile If IsArray ($FolderList) Then _ArrayDisplay ($FolderList) Else MsgBox (0,"", "FolderList isn't an array -> Error") EndIf ;-)) Stefan Link to comment Share on other sites More sharing options...
exodius Posted October 5, 2009 Share Posted October 5, 2009 (edited) Try using: Ubound(FolderList)-1 On a relative note, why don't you just do: $FolderList = _FileListToArray($PathToBuild, "*", 2) For $d = 1 To $FolderList[0] If @error = 0 Then DirRemove($PathToBuild & "\" & $FolderList[$d], 1) EndIf Next Edited October 5, 2009 by exodius Link to comment Share on other sites More sharing options...
oshaker Posted October 5, 2009 Author Share Posted October 5, 2009 I had to restart PC and it works fine really strange... Link to comment Share on other sites More sharing options...
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