HelpUsers Posted July 30, 2008 Share Posted July 30, 2008 (edited) Hi, My probleme is the following. I want to scan files in a folder which can contain sub-folders and files. If my folder is empty (without files or folders) this function hangs : $Files=_FileListToArray("C:\Scan","*",1) <== flag=1 is for files only Msgbox(64,"Count Files","In this folder, there is : " & $Files[0]) ^ <== hangs here because no files are in this folder There is no problem if the folder contains a least one sub-folder !!! I think $Files[0] returns the number of elements in the folder (sub-folder and files), but why $Files[0] doesn't return 0 if no file is present ? Have you an idea ? Thanks For information, I use AutoIt Version: 3.2.12.1. Edited July 30, 2008 by HelpUsers Link to comment Share on other sites More sharing options...
Dampe Posted July 31, 2008 Share Posted July 31, 2008 $Files=_FileListToArray("C:\Scan","*.*",1) <== flag=1 is for files only Msgbox(64,"Count Files","In this folder, there is : " & $Files[0]) ^ <== hangs here because no files are in this folde I think it needs a *.* wildcard, not * Link to comment Share on other sites More sharing options...
smashly Posted July 31, 2008 Share Posted July 31, 2008 (edited) $Files = _FileListToArray("C:\Scan", "*", 1) If @error Then Msgbox(64,"Error !", "Error Code: " & @error) Else Msgbox(64,"Count Files","In this folder, there is : " & $Files[0]) EndIf @Dampe.. " *" is a wildcard... it's actually the Default value used in the _FileListToArray() function. Edited July 31, 2008 by smashly Link to comment Share on other sites More sharing options...
HelpUsers Posted July 31, 2008 Author Share Posted July 31, 2008 $Files = _FileListToArray("C:\Scan", "*", 1) If @error Then Msgbox(64,"Error !", "Error Code: " & @error) Else Msgbox(64,"Count Files","In this folder, there is : " & $Files[0]) EndIf @Dampe.. " *" is a wildcard... it's actually the Default value used in the _FileListToArray() function. I've already tried both "*" and "*.*" before post in this forum, but it still not working. Do you think the problem can be in file.au3 for the '_FileListToArray' function ? Thanks Link to comment Share on other sites More sharing options...
TerarinKerowyn Posted July 31, 2008 Share Posted July 31, 2008 _FileListToArray function runs normally but there is some aspects that you didn't clear. Do you have C:/Scan as a directory on your computer or any files in there? If either of these is true then you should get a error coding for 1. This works:$Files = _FileListToArray("C:\", "*", 1) If @error Then Msgbox(64,"Error !", "Error Code: " & @error) Else Msgbox(64,"Count Files","In this folder, there is : " & $Files[0]) EndIfBut what you want you'll have to ensure it is createdIf FileExists("C:\Scan") Then $Files = _FileListToArray("C:\Scan", "*", 1) If IsArray($Files) Then MsgBox(64, "Count Files", "In this folder, there is : " & $Files[0])) Else MsgBox(64, "Count Files", "In this folder, there is : 0") EndIf EndIfFirst I check if the directory is created and if it is run _FileListToArray and store it in $Files. Now what I did was check to see what it is, a array would mean the function worked those getting the Files[0] size. Then that leaves 0 being a error the only true problem that you could have are Invalid $sFilter or Invalid $iFlag while running the function Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah Link to comment Share on other sites More sharing options...
HelpUsers Posted July 31, 2008 Author Share Posted July 31, 2008 (edited) I've tried your example. Thanks But it still not working correctly if C:\scan contains only sub-folder(s) but no files. I've modified your script to make this : While 1 $FILES=_FileListToArray("C:\Scan", "*", 1) If IsArray($FILES)=1 Then ; select if scan object is a file or a folder Select ; If number of files is >0 Case $FILES[0]>0 ExitLoop ; If folder Case Else EndSelect EndIf WEnd ; Script continue only if a file has been found I think it can be useful for other users Edited July 31, 2008 by HelpUsers Link to comment Share on other sites More sharing options...
TerarinKerowyn Posted July 31, 2008 Share Posted July 31, 2008 (edited) See you have a problem then because then you goto create the directory if it doesn't exist A more up-to-date function CODE#include <File.au3> $s_Directory = "" If FileExists($s_Directory) Then $a_Files = _FileListToArray("$s_Directory", "*", 1) MsgBox(0, "", "Test") If IsArray($a_Files) Then If $a_Files[0] > 0 Then MsgBox(64, "Count Files", "In this folder, there is : " & $Files[0]) Else MsgBox(64, "Count Files", "In this folder, there is : " & $s_Directory & " has no files") EndIf Else MsgBox(64, "Count Files", "In this folder, there is : 0") EndIf Else MsgBox(64, "Count Files", "There is no " & $s_Directory & " folder") EndIf Edited July 31, 2008 by TerarinKerowyn Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah 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