Sign in to follow this  
Followers 0
ahha

Directory listing

14 posts in this topic

I'm sure someone has done this and hate to reinvent.

I need something like what this batch file produces.

dir c:*.* /s/b > c:\dir_list.txt

which is just a complete listing of path+filename for all files on a drive put into a text file.

Thanks

Share this post


Link to post
Share on other sites



I'm sure someone has done this and hate to reinvent.

I need something like what this batch file produces.

dir c:*.* /s/b > c:\dir_list.txt

which is just a complete listing of path+filename for all files on a drive put into a text file.

Thanks

RunWait(@ComSpec & ' /c dir c:*.* /s/b > c:\dir_list.txt",'',@SW_HIDE)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I'm sure someone has done this and hate to reinvent.

I need something like what this batch file produces.

dir c:*.* /s/b > c:\dir_list.txt

which is just a complete listing of path+filename for all files on a drive put into a text file.

Thanks

HI,

you could run that command with _RunDos()... :D

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Welcome to the forums!

dir c:*.* /s/b > c:\dir_list.txt

which is just a complete listing of path+filename for all files on a drive

Keep in mind that c:*.* is a relative path. You'll only get a listing for the current directory onward.

To get the full drive, use c:\*.*


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Welcome to the forums!

Keep in mind that c:*.* is a relative path. You'll only get a listing for the current directory onward.

To get the full drive, use c:\*.*

Thanks all. Skruge thanks for the reminder on the backslash.

I thought there might be a program coded in Autoit that walked the directory rather than having to dive into DOS.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks all. Skruge thanks for the reminder on the backslash.

I thought there might be a program coded in Autoit that walked the directory rather than having to dive into DOS.

This should do what you want although it does not list files alphabetically as such files are listed in order by windows "Table Of Contents" FileFindNextFile

$logfile = FileOpen ("C:\DirectoryList.txt",2)
Search ("c:");replace with your search directory

Func Search($current)

    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
        
        If $current & "\" & $file <> "C:\DirectoryList.txt"  then FileWriteLine ($logfile,$current & "\" & $file)
            
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            Search($current & "\" & $file)
            
        EndIf
    WEnd
    FileClose($search)

EndFunc

Func OnAutoitExit()
    FileClose ($logfile)
EndFunc
Edited by ChrisL

Share this post


Link to post
Share on other sites

Thanks all. Skruge thanks for the reminder on the backslash.

I thought there might be a program coded in Autoit that walked the directory rather than having to dive into DOS.

Hi,

Speed is the issue;

See various solutions under "recursive" link below in my sig; but running DOS is heaps quicker!

Best, Randall

Share this post


Link to post
Share on other sites

Chris - thanks. For some reason I keep getting this when I run it.

"Unable to open file, the maximum number of open files has been exceeded.:

Local $search = FileFindFirstFile($current & "\*.*")"

I'll recheck the code and try and figure it out.

This should do what you want although it does not list files alphabetically as such files are listed in order by windows "Table Of Contents" FileFindNextFile

$logfile = FileOpen ("C:\DirectoryList.txt",2)
Search ("c:");replace with your search directory

Func Search($current)

    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
        
        If $current & "\" & $file <> "C:\DirectoryList.txt"  then FileWriteLine ($logfile,$current & "\" & $file)
            
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            Search($current & "\" & $file)
            
        EndIf
    WEnd
    FileClose($search)

EndFunc

Func OnAutoitExit()
    FileClose ($logfile)
EndFunc

Share this post


Link to post
Share on other sites

Chris - thanks. For some reason I keep getting this when I run it.

"Unable to open file, the maximum number of open files has been exceeded.:

Local $search = FileFindFirstFile($current & "\*.*")"

I'll recheck the code and try and figure it out.

The problem with Chris's code is that it is calling the function Search() within itself before closing handles and opening new handles. This will make the error of too many open files.

Calling a function within itself is not healthy code. Recursion errors can happen also from this method. Either use the Dir command built within ComSpec (as randallc has pointed to) or have a look for Larry's FileSearch UDF in Scripts'n'Scraps.

:D

Share this post


Link to post
Share on other sites

MHz - I saw that and tried to figure out how to insert a FileClose so that it did not remain open with too many files. I'll search for Larry's code. Thanks.

The problem with Chris's code is that it is calling the function Search() within itself before closing handles and opening new handles. This will make the error of too many open files.

Calling a function within itself is not healthy code. Recursion errors can happen also from this method. Either use the Dir command built within ComSpec (as randallc has pointed to) or have a look for Larry's FileSearch UDF in Scripts'n'Scraps.

:D

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Chris - thanks. For some reason I keep getting this when I run it.

"Unable to open file, the maximum number of open files has been exceeded.:

Local $search = FileFindFirstFile($current & "\*.*")"

I'll recheck the code and try and figure it out.

I'll bet you are not using the beta version. I tried this on my entire c: drive and it is fine.

If you have a 64 level deep recursion of folders I'd be supprised

Also if you close the filehandles before they are ready it cant find the next file, try my code with the latest beta http://www.autoitscript.com/autoit3/files/beta/autoit/

Edited by ChrisL

Share this post


Link to post
Share on other sites

ChrisL - okay as a newbie I have a target on my back. Go ahead and shoot me. I have several versions of AutoIt installed. I'm using SciTE, so how do I make sure it's pointing to a particular AutoIt version? Thanks. ahha

I'll bet you are not using the beta version. I tried this on my entire c: drive and it is fine.

If you have a 64 level deep recursion of folders I'd be supprised

Also if you close the filehandles before they are ready it cant find the next file, try my code with the latest beta http://www.autoitscript.com/autoit3/files/beta/autoit/

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

MsgBox(0,"Version", @AutoItVersion)

Edited by Skruge

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

ChrisL - okay as a newbie I have a target on my back. Go ahead and shoot me. I have several versions of AutoIt installed. I'm using SciTE, so how do I make sure it's pointing to a particular AutoIt version? Thanks. ahha

In scite go Tools/Betarun

When the script finishes I beleive it tells you the autoit version in the output from scite

If you put the messgae box in that skruge suggested this will also tell you

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  
Followers 0