webjocky Posted September 19, 2006 Share Posted September 19, 2006 (edited) Array n00b here -I am trying to list all of the files of a certain file-type from a certain directory into an array - without knowing how large the array needs to be.For example:Let's say I have a directory "C:\temp\" and there are three files in this directory (but we can't count on only three files being there all the time, could be over 100 files there, we just don't know)test.exesomename.loganothername.logI need the array to contain the filenames of only the ".log" files.I have a good idea that it will probably use the following functions:#include <Array.au3> _ArrayCreate() FileFindFirstFile() FileFindNextFile()along with a loop and some error traps - but I have been at this for hours on end, and can't seem to get things 'just right'.Thanks in advance for ANY helpEdit: Just wanted to add that I have searched the forums for anything covering something similar and have come up empty handed Edited September 19, 2006 by webjocky The tiniest of things can ruin your day, or brighten your afternoon. Read it once, read it again, and pay attention. Then search the forums. If all else fails, ask somebody else. Link to comment Share on other sites More sharing options...
Marc Posted September 19, 2006 Share Posted September 19, 2006 (edited) $pattern = "*.log" Dim $array[1] $handle = FileFindFirstFile($pattern) If $handle = -1 Then MsgBox(4096, "Error", "No files found") Exit EndIf $counter=0 While 1 $file = FileFindNextFile($handle) If @error Then ExitLoop $counter = $counter +1 ReDim $array[$counter] $array[$counter-1]=$file Wend FileClose($handle) $result="" for $i= 0 to UBound($array)-1 $result = $result & $array[$i] & " " Next MsgBox(0, $result,"Amound of Files: " & UBound($array)) Edited September 19, 2006 by Marc Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Uten Posted September 19, 2006 Share Posted September 19, 2006 How about using _FileListToArray(...) Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Marc Posted September 19, 2006 Share Posted September 19, 2006 °oO( Cheater ) Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Uten Posted September 19, 2006 Share Posted September 19, 2006 And proud of it Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Marc Posted September 19, 2006 Share Posted September 19, 2006 *pwned* Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
webjocky Posted September 19, 2006 Author Share Posted September 19, 2006 heh, thanks guys. Kudos to Marc for doing a lot of legwork, Uten just pulled a shortcut out of his back-pocket - Show-off But they'll both do the trick and thanks for that! The tiniest of things can ruin your day, or brighten your afternoon. Read it once, read it again, and pay attention. Then search the forums. If all else fails, ask somebody else. 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