Jump to content

Directory Crawler


Recommended Posts

Yo; anyways...ive been trying to make a simple directory crawler that would filewriteline() about what files it found

this is my try at it

$Dir = @ScriptDir
$Dr1 = $Dir
$A = FileFindFirstFile("*.*")
while 1
$B = FileFindNextFile($A)
$C = StringSplit(FileGetLongName($B,1),".")
If @error = 0 Then
If $C[0] >= 2 Then
If $C[2] = "zzt" Or $C[2] = "au3" Then
Else
    FileWriteLine("text.zzt",$Dir&"\"&$B)
EndIf
EndIf
EndIf
    If $C[0] = 1 And $B = Not "" Then
        $Dir = $Dir&"\"&$B
    EndIf
    If $B = "" Then
        If $Dir = $Dr1 Then
            ExitLoop
        EndIf
        $A = FileFindFirstFile($Dir&"\*.*")
        $Dr1 = $Dir
        $B = ""
    EndIf
WEnd

the text.zzt was the file it was writeing to as you can see

it works if it only has 1 folder to another...IE

C:\1\1.txt
C:\1\2\2.txt
C:\1\2\3\3.txt

that would work but if any of them have a 2nd Dir it fails...any ideas?

also i know i coulda just done If not yada yada yada but im lazzy so i just left teh big piles of if's

EDIT!!!

Woot!! I Solved it

$Dir = @ScriptDir
$Dr1 = $Dir
$Dr2 = 0
dim $Dr[100]
$A = FileFindFirstFile("*.*")
while 1
$B = FileFindNextFile($A)
$C = StringSplit(FileGetLongName($B,1),".")
If @error = 0 Then
If $C[0] >= 2 Then
If $C[2] = "zzt" Or $C[2] = "au3" Then
Else
    FileWriteLine("text.zzt",$Dir&"\"&$B)
EndIf
EndIf
EndIf
    If $C[0] = 1 And $B = Not "" Then
        If $Dr2 = 1 Then
            $Dr[0] += 1
            $Dr[$Dr[0]] = $Dr3&"\"&$B
        Else
        $Dr3 = $Dir
        $Dr2 = 1
        $Dir = $Dir&"\"&$B
        EndIf
    EndIf
    If $B = "" Then
        $Dr2 = 0
        If $Dir = $Dr1 Then
            If $Dr[0] = Not 0 Then
                $Dir = $Dr[$Dr[0]]
                $Dr[0] -= 1
                $Dr2 = 0
            Else
            ExitLoop
            EndIf
        EndIf
        $A = FileFindFirstFile($Dir&"\*.*")
        $Dr1 = $Dir
        $B = ""
    EndIf
WEnd

now its time to optimize it

Edit Again

That was the best i could do lol

Edited by xZZTx
Sorry For Any Spelling / Grammar Errors I May Make.... I Failed English Wayyyy To Many Times..
Link to comment
Share on other sites

  • Moderators

xZZTx,

Try searching for "recursive file search". There are plenty of examples out there. I would do it for you , but I too am feeling a bit lazy........ ;-)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 months later...

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
 Share

  • Recently Browsing   0 members

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