BillLuvsU Posted March 16, 2005 Share Posted March 16, 2005 Is it possible to get a list of file and folders in a folder and return it into a array? [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
automagician Posted March 16, 2005 Share Posted March 16, 2005 I'm sure there is a better way, but how I did it in the past was I did a 'dir' in a hidden DOS window and redirected to a file, and did a '_FileReadToArray' on the file. Let me know if you find a better way Link to comment Share on other sites More sharing options...
CyberSlug Posted March 16, 2005 Share Posted March 16, 2005 Yes. That would be a useful function... I'll see what I can come up with. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
BillLuvsU Posted March 16, 2005 Author Share Posted March 16, 2005 Also, I was wondering if anybody has come up with a function to get text that comes after something. Like finding out what it says after readrl or something. [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
CyberSlug Posted March 16, 2005 Share Posted March 16, 2005 (edited) There are a bunch of methods; I stayed from StringSplit since it might be inefficient; you could also use the StdIO-redirection in the beta if you wanted to use the 'dir' command. $foo = _DirToArray(@ScriptDir) $temp = "" For $i = 0 to UBound($foo)-1 $temp = $temp & $i & @TAB & $foo[$i] & @CRLF Next MsgBox(4096,UBound($foo) & " items", $temp) Exit Func _DirToArray($folder, $filters = "*.*") Local $dirInfo = DirGetSize($folder, 3);non-recursive extended info flag Local $count = $dirInfo[1] + $dirInfo[2] ;number of files and folders Local $search = FileFindFirstFile($folder & "\" & $filters) If $search = -1 Then SetError(1) Return 0 EndIf Local $output[$count] Local $i = 0 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = "." or $file = ".." Then ContinueLoop $output[$i] = $file $i = $i + 1 Wend ReDim $output[$i] Return $output EndFunc Edit: To answer your other question, have you looked at StringInStr? Edited March 16, 2005 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
automagician Posted March 16, 2005 Share Posted March 16, 2005 Here's my version if anyone was interested, although it's not nearly as cool as cyberslugs : #Include <process.au3> #include <file.au3> $dir = "C:\" $foo = _Foo($dir) Func _Foo($loc) Local $array Local $file = "C:\\abc.txt" _RunDOS("dir /B " & $loc & " > " & $file) _FileReadToArray($file, $array) FileDelete($file) Return($array) EndFunc Link to comment Share on other sites More sharing options...
ennis Posted March 16, 2005 Share Posted March 16, 2005 Im guessing u dont want to list subdirectories and their files as well? Let me know...I may have smthng for that. Link to comment Share on other sites More sharing options...
automagician Posted March 17, 2005 Share Posted March 17, 2005 How embarrassing.... Yes, that slipped my mind. I believe back when I was doing it I was only concerned with the files. Regardless, I would be interested in what you have for subdirectories and their files. Link to comment Share on other sites More sharing options...
CyberSlug Posted March 17, 2005 Share Posted March 17, 2005 Use the /S switch to traverse subdirectories. I'm too lazy to implement that in my code right now. _RunDOS("dir /B /S " & $loc & " > " & $file) Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
automagician Posted March 17, 2005 Share Posted March 17, 2005 Easy enough... You can even use /O to sort in whatever order you'd like them to be listed. Well that about covers that Link to comment Share on other sites More sharing options...
keeskas Posted March 17, 2005 Share Posted March 17, 2005 Easy enough...You can even use /O to sort in whatever order you'd like them to be listed.Well that about covers that <{POST_SNAPBACK}>if you want to do some tricks with every file or dir, try "forfiles" it's part of w2k3i used it together with the setowner tool to get all the fileowners in a certain directory.greetingsKees 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