Sign in to follow this  
Followers 0
Diana (Cda)

List files of certain type, recursively.

6 posts in this topic

#1 ·  Posted (edited)

After months of tedious searching through the help file and the forum for every single thing I come up with in AI, today I get fed up a lot earlier and gave up looking for exactly what I needed with a purely AI solution. But it's all written in AI, so I'm very pleased. I couldn't figure out all the array stuff this morning after over an hour of study <sigh>, and that's what made me turn back to an old standby, a bat file. I used to use simple batch files long before AutoIt was around even though I find it on the whole infinitely harder to understand than AutoIt <vbg>. But in some things, it's simplicity itself just like in the batch file here (batch syntax is a simple: DIR *.ini /s /on /b > filelist.txt).

This method is for other newbies like me. I'm sure the experts can do a heck of a lot better, but this will get the job done. I periodically need to get an updated list of the INI files in subfolders of the root this script is stored in. The neat thing is that although the list work is all done by the bat, the rest is pure AI and, as such, has all the greater flexibility of where you write the txt file, too, etc., and all the lovely relative path options available to AutoIt.

It's all self-contained. The script creates the bat, invokes it, creates the list in a text file which it then transfers over to a blank notepad page and then, the ultimate for me, deletes both the batch file and the resulting text file so all you're left with is a notepad page with the information you need. Gotta love htat <g>.

All the above can be modified to suit lots of other conditions, but if anyone's aim is to leave no documents behind besides the original script, then that's what happens here. (Pls ignore any of my idiosyncratic syntax that I always keep in my scripts.)

;
; AutoIt 3x
;
#include <_PartitionLetters.au3>     ; this replaces drive letters
#include<_WEReplacement.au3>     ; references a Windows Explorer replacement program
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 146)     ; changes the icon displayed in the systray
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!

;------------------------------------------------------------------------------------------------------
;  1. Creates BAT file (switches from http://www.computerhope.com/dirhlp.htm):
;  SWITCHES:  DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
;                 [drive:][path][filename] Specifies drive, directory, and/or files to list. 
;                       attributes-
;                                D  Directories
;                                R  Read-only files
;                                H  Hidden files
;                                A  Files ready for archiving
;                                S  System files
;                                -  Prefix meaning not
;                 /B Uses bare format (no heading information or summary).
;                 /C Display the thousand separator in file sizes. This is the default. Use /-C to disable display of separator.
;                 /D Same as wide but files are list sorted by column.
;                 /L Uses lowercase.
;                 /N New long list format where filenames are on the far right.
;                 /O List by files in sorted order.
;                       sortorder- 
;                                N  By name (alphabetic)
;                                S  By size (smallest first)
;                                E  By extension (alphabetic)
;                                D  By date/time (oldest first)
;                                G  Group directories first
;                                -  Prefix to reverse order
;                 /P Pauses after each screenful of information.
;                 /Q Display the owner of the file.
;                 /S Displays files in specified directory and all subdirectories.
;                 /T Controls which time field displayed or used for sorting
;                 Timefield-
;                       C Creation
;                       A Last Access
;                       W Last Written
;                 /W Uses wide list format.
;                 /X  This displays the short names generated for non-8dot3 file names.  The format is that of /N with the short name inserted before the long name.
;                      If no short name is present, blanks are displayed in its place. 
;                 /4 Displays four-digit years 
FileWrite(@ScriptDir & "\SKINS dir list.bat", "DIR *.ini /s /on /b > filelist.txt")
;------------------------------------------------------------------------------------------------------
;  2.  Launch it:
If FileExists(@ScriptDir & "\SKINS dir list.bat") Then ShellExecute(@ScriptDir & "\SKINS dir list.bat")
Sleep(250)
;------------------------------------------------------------------------------------------------------
;  3.  Read contents of list text file:
$FILE = @ScriptDir & "\filelist.txt"
$READ = FileRead($FILE)

If FileExists(@ScriptDir & $FILE) Then $READ
    FileClose($FILE)
    ClipPut($READ)
ShellExecute("notepad.exe", "", "", "open", @SW_MAXIMIZE)     ; launches notepad, maximized
WinWait("Notepad")
WinActivate("Notepad")
Send("^n")
WinWait("Untitled - Notepad")
Send ("^v")
Send("{CTRLDOWN}{HOME}{CTRLUP}")     ; cursor to top of screen


If FileExists(@ScriptDir & "\filelist.txt") Then FileDelete(@ScriptDir & "\filelist.txt")
If FileExists(@ScriptDir & "\SKINS dir list.bat") Then FileDelete(@ScriptDir & "\SKINS dir list.bat")
Hope it's of use to anyone else. I've needed something like this for a long time but didn't know and still don't know how to do it all in AI since all that array stuff if really confusing to me still.

Cheers. :P

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites



-Snipped-

Hope it's of use to anyone else. I've needed something like this for a long time but didn't know and still don't know how to do it all in AI since all that array stuff if really confusing to me still.

Cheers. :P

Have you tried reading the wiki-page about arrays?? Maybe that can help you understand them :P

Share this post


Link to post
Share on other sites

Pretty much every FileListToArray function found in Example Scripts does this for you.

http://www.autoitscript.com/forum/index.ph...filelisttoarray

Thanks. But I have to mention that this was one of the posts that I found before posting this thread. In particular, the MP3 example one seemed best one to try to get to work, modified. As I mentioned at beginning, I did an _extensive_ search already both in forum and in help file. This wasn't only post, either. However, when I get to the point that I _can_ modify such complex scripts (for me), then, sure, that will be true.

Thanks at any rate. Cheers. :P

Share this post


Link to post
Share on other sites

Have you tried reading the wiki-page about arrays?? Maybe that can help you understand them :P

Thanks! It lately has amazed me at how long it's taken to find great resources! Like with the Code Wizard or Koda, wish I'd known of these wiki pages sooner! But this is fantastic. I'll definitely look for solutions here now, too! It seems like the type of thing someone like me needs!

Neither fish nor fowl, is what I am. Tons of experience (I'm a power user) in so many different areas of computer use, but am still definitely at a disadvantage when "programming" as have never really gotten beyond the basics in a handful of scripting situations. Never had time to and, up until last few years, really was no real, great need to. It's only as work has become so much more complex that I need AI programming solutions to speed things up so that I can keep on top of the ever-increasing demands they make at work. I've automated whatever I could logically do so to help reduce workload. You guys have no concept of what I've done with AI, not that you'd probably be at all interested <g>, but the number of my posts indicates only the tip of the iceberg of what I then do with whatever new code I learn <g>.

So this page you recommend is great. And I particularly like this line in the INITIAL NOTES:

"This is a small tutorial on how to use arrays in AutoIt.

We will try to target those people learning a programming language for the first time. So, be prepared for some spoon feeding."

<wince> 'spoon feeding' <sigh> Yes, that's sort of exactly what one sometimes needs whenever a new bit of code comes along. Too many times in this forum, the particular line of syntax I'm trying to figure out is embedded amongst a whole bunch of other, extraneous (for me) and confusing code when taken in as a whole. I never have _any_ difficulty understanding the concepts and even, to a certain degree, the mechanics involved. Where I get stumped repeatedly is knowing how to modify code; what word goes where, what punctuation goes where, etc., etc. and even what additional syntax has to be used to fulfill a different goal in using the code than what the post intended it for.

So if there are wiki pages like this for most of the functions one does in AI that provide explanations on a more basic level for whenever I get this stumped with this array business or like another issue concerning adlib, then that's super and I can't thank you enough! I apologize but I didn't know about this wiki resource before. Unbelievably, they never came up in any search I've ever done. I really, really appreciate you pointing this out to me!

Cheers! :P

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi, Lady Diana!

If you want wrap the DIR command more fast, look this example:

#include <Array.au3>

$r=fastwrapdir("C:\temp\*.jpg D:\Divprog\*.exe C:\temp\*.exe")
_ArrayDisplay($r)
Exit

Func fastwrapdir($patterns)
    $result=""
    $pid = Run("cmd /cdir " & $patterns &" /B /S /A:H /A:S /A:-D","",0,6)
    While 1
        $result &= StdoutRead($pid)
        If @error Then ExitLoop
    Wend
    $ar=StringSplit($result,@CRLF,1)
    _ArrayPop($ar)
    $ar[0]-=1
    return($ar)
EndFunc

(multidir, recurse, no file, fast because DIR remains internal)

Edited by Michel Claveau

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