Jump to content

Recommended Posts

Posted

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

Posted

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 :)

Posted

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

Posted (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 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!
Posted

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
Posted

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.

Posted

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 w2k3

i used it together with the setowner tool to get all the fileowners in a certain directory.

greetings

Kees

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...