Jump to content
Sign in to follow this  
dimchik

Folder list

Recommended Posts

dimchik

May be some one could suggest how can i write a program which searches drive only 3 levels deep and returns folder with full path.

Ex I have t drive

T:\Client\Project_name\Project

Soi want to scan and return only

T:\Client\Project_name\Project1

T:\Client\Project_name\Project2

T:\Client\Project_name\Project3

T:\Client2\Project_name2\Project

etc

I owuld like to scan only folders i do not need files.

Thank you for any help.

Share this post


Link to post
Share on other sites
Prab

I just did something similar to this recently. I goes deeper than three levels, but just adding another parameter to the recursion should control that. Feel free to use this as a starting point and delete what you don't need.

Edit: Looking over my code, I didn't comment it very well. If you have questions just ask.

#include <GUIConstantsEx.au3>
; Shows the filenames of all files in the current directory.

If ($CmdLine[0] > 0) Then
    $var = $CmdLine[1]
Else
    $var = FileSelectFolder("Choose a folder to scan.", "", 0, "c:\")
    If (@error == 1) Then
        MsgBox(0, "Error", "That folder cannot be selected.")
        Exit
    EndIf
EndIf

$search = FileFindFirstFile($var & "\*.*") 
If ($search == -1) Then
    MsgBox(0, "Error", "The folder could not be opened.")
    Exit
EndIf

; Check if the search was empty
If (@error == 1) Then
    MsgBox(0, "Error", "The folder is empty")
    Exit
EndIf

$gui = GUICreate("Scanning Folder")
$label = GUICtrlCreateInput("Line 1 Cell 1", 10, 10, 800)
GUISetState(@SW_SHOW)

$fileCount = 0

$answer = search($search, $var)
$answer = "You have " & $fileCount & " files and folder in " & $var & @CRLF & @CRLF & $answer

FileClose($search)

$temp = FileSaveDialog("Choose where to save the log", @DesktopDir & "\", "Log (*.log;*.txt)", 16, "files.log")
If (@error == 1) Then
    Exit
EndIf

$file = FileOpen($temp, 2)
If ($file == -1) Then
    MsgBox(0, "Error", "Could not save file.")
    Exit
EndIf

FileWriteLine($file, $answer)
FileClose($file)

Func search($search, $var)
$toReturn = ""
While (True)
    $file = FileFindNextFile($search) 
    If @error Then
        ExitLoop
    EndIf
    
    $toReturn = $toReturn & $var & "\" & $file & @CRLF
    $fileCount += 1
    If mod($fileCount, 10) = 0 Then;only update the display every 10 files; helps speed
        GUICtrlSetData($label, $var & "\" & $file)
    EndIf
    
    $attrib = FileGetAttrib($var & "\" & $file)
    If StringInStr($attrib, "D") Then
        $search2 = FileFindFirstFile($var & "\" & $file & "\*.*")
        $toReturn = $toReturn & search($search2, $var & "\" & $file)
    EndIf
    
WEnd

return $toReturn
EndFunc
Edited by Prab

Share this post


Link to post
Share on other sites
dimchik

Is it possible to controll not to scan files only folders and only 3 levels deep as i have over 70million files ill be listing for 5 days.

Share this post


Link to post
Share on other sites
Prab

$search = FileFindFirstFile($var & "\*.*")

and

If StringInStr($attrib, "D") Then

Controls what kinds of files/folders it scans. "D" stands for Directory.

--------------

Edit

Func search($search, $var)

to be something more like

Func search($search, $var, $depth)
If ($depth > 3) then 
return $toReturn
EndIf(

and

toReturn = $toReturn & search($search2, $var & "\" & $file)

to be more like

toReturn = $toReturn & search($search2, $var & "\" & $file, $depth + 1)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.