Willow Posted August 13, 2010 Share Posted August 13, 2010 When running this code, it will randomly fail with the error message: Line -1: Error: Subscript used with non-Array variable. Any help in finding the cause is appreciated. $archive_folder = "C:\Archived backups" IF NOT FileExists($archive_folder) THEN DirCreate($archive_folder) $arc = "C:\data" $FoldersToMove = "backup*" $FolderArray = _FileListToArray( $arc, $FoldersToMove, 2) For $i = 1 To $FolderArray[0] DirMove($arc & "\" & $FolderArray[$i], $archive_folder & "\" & $FolderArray[$i], 1) Next Link to comment Share on other sites More sharing options...
BigDaddyO Posted August 13, 2010 Share Posted August 13, 2010 because if it doesn't find any files, the variable is not an array. You need to put in if @error then error message or something... else Run your loop endif Link to comment Share on other sites More sharing options...
Willow Posted August 13, 2010 Author Share Posted August 13, 2010 Thanks, Mike, Not sure I quite follow what you mean. I now realize the array is failing because there are no files,however I don't need to display an error message, the code just needs to continue past this as it will be running unattended and finding no file(s) is not a worry as sometimes there will be files, other times there will be not. Link to comment Share on other sites More sharing options...
BigDaddyO Posted August 13, 2010 Share Posted August 13, 2010 (edited) ok, in that case I would use if Not @error then. I don't think your supposed to use if not due to some performance issues in the milliseconds but i havn't had a problem. So your code should be like $archive_folder = "C:\Archived backups" IF NOT FileExists($archive_folder) THEN DirCreate($archive_folder) $arc = "C:\data" $FoldersToMove = "backup*" $FolderArray = _FileListToArray( $arc, $FoldersToMove, 2) if not @error then For $i = 1 To $FolderArray[0] DirMove($arc & "\" & $FolderArray[$i], $archive_folder & "\" & $FolderArray[$i], 1) Next endif Edited August 13, 2010 by MikeOsdx Link to comment Share on other sites More sharing options...
UEZ Posted August 13, 2010 Share Posted August 13, 2010 #Include <File.au3> #Include <Array.au3> $archive_folder = "C:\Archived backups" IF NOT FileExists($archive_folder) THEN DirCreate($archive_folder) $arc = "C:\data" $FoldersToMove = "backup*" $FolderArray = _FileListToArray( $arc, $FoldersToMove, 2) If Not @error And IsArray($FolderArray) Then For $i = 1 To $FolderArray[0] DirMove($arc & "\" & $FolderArray[$i], $archive_folder & "\" & $FolderArray[$i], 1) Next Else MsgBox(16, "Error", "An error has occured!") EndIf Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ 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