Sign in to follow this  
Followers 0
Ascend4nt

_FileFindEx - Get More from File/Folder Searches

33 posts in this topic

#1 ·  Posted (edited)

_FileFindEx

Get More from File/Folder Searches

(formerly _WinAPI_FileFind)

Since it's always bugged me that the AutoIT implementation of 'FindFirstFile' and 'FindNextFile' only returned filenames and that extra calls had to be made to get file-size, attributes, short-names, and date/time of file creation,last-access, & last-modification which severely increased the amount of time it took to properly analyze the contents of a folder and it's files, I decided to create an alternative.

This uses the same Windows calls as AutoIT, except it returns all the information that it rightfully should for each file found - including:

  • File attributes (in numerical form, not a silly string format)
  • Creation Time
  • Last-Access Time
  • Last-Write Time
  • FileSize
  • Filename (obviously)
  • 8.3 short name (if it is 1. different from the regular Filename and 2. if short-names haven't been turned off
  • Reparse Point info (if available)
Now, the calling process is a little different, though for the most part not much is required to be altered in existing code. Basically, the attributes-check for folders is a numerical test, and when a folder is found, you *need* to test for '.' and '..' navigation (fake) folders. Also, the 'While' loop changes into a 'Do-Until' loop. Additionally, the first _FileFindExFirstFile() call returns a file, whereas FileFindFirstFile() doesn't (which never made sense to me).

To convert times into a readable format, you'll need to pass the array to the _FileFindExTimeConvert() function. Optionally, you can get the _WinTimeFunctions UDF and call those functions using array index constants:

$FFX_CREATION_TIME, $FFX_LAST_ACCESS_TIME, or $FFX_LAST_MODIFIED_TIME.

Note all _FileFindEx* calls are done using a special array, though 'ByRef' for quicker performance.

A nice application I found for this UDF was comparing files/folders - which is pretty easy using 64-bit filetime and file-size comparisons (no need for time conversion there).

The ZIP includes 4 files: the _FileFindEx UDF, FileFindExTest, the license agreement (same as below), and _LinkedOutputDisplay. Please note that _LinkedOutputDisplay on its own is a mess - but its included as-is to help see a side-by-side comparison of the output from FileFindExTest.

To get all the same information that _FileFindEx provides, the AutoIt functions below would need to be called:

  • FileFindFirst/NextFile
  • FileGetAttrib *** NOTE: This Fails to report on some attributes (Reparse Points, Sparse Files) ***
  • FileGetTime *3 (one for each time - Creation, Last-Access, Last-Modified)
  • FileGetSize
  • FileGetShortName (note: this provides a full path, rather than just a file name)
Please note that for a fair time comparison, a clean boot is needed for each test due to O/S buffering after a scan. Between boots, the order of function calls in 'FileFindExTest' would need to be swapped. In first-run tests, _FileFindEx has consistently been quicker when gathering more than basic filename info. However, running the UDF in 64-bit mode on Vista+ O/S's results in slower performance, hence this note:

*IMPORTANT* - Speed is severely affected on certain processors when the script is run in x64 mode. I therefore recommend running/compiling the code in both bit-modes beforehand to see what the speed difference is. On my machine I've found x86 is much faster, whereas x64 is much slower than AutoIt's search functions. Other's have so I'm guessing it must be how optimized the hardware architecture is at running x64 code.

Update Log:

  • 5/24/2011: Further speed optimization when using _FileFindExTimeConvert().
  • 5/23/2011: New name, faster execution!

    * Removed: _WinTimeFunctions UDF. No longer needed (see below).

    * Added: New array element for REPARSE Points that are located ($aFind[7]).

    * Added: Internal time-conversion function removes the need for _WinTime* calls. This results in a solid increase in performance.

    * SCRIPT-BREAKING CHANGES *: Function-names changed - A simple search&replace should work here.

  • 5/9/2010: New version with better 64-bit FileTime support, bundled separate example with output display, and the _WinTimeFunctions required module (+ example use). All code falls under the same License agreement! AutoIT v3.3.6+ required.
  • - Updated for AutoIT v3.3 support (or 3.2.12.1 UNICODE-only)

Download the ZIP Here

Ascend4nt's AutoIT Code License agreement:

While I provide this source code freely, if you do use the code in your projects, all I ask is that:

  • If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I credit
  • If the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)
  • The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.
  • Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.
Edited by Ascend4nt

Share this post


Link to post
Share on other sites



@ascendant

Great and useful job ! :P

Five stars from me :unsure:

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Thanks guys =)

@ptrex - that really annoys me that they removed that, arghh.. I'm still clinging to 3.2.12.1, even though I haven't found myself coding for anything ANSI lately, and I keep modifying the 3.2.12.1 WinAPI functions to include error handling hehe. I guess I should just make the switch and never look back!

Win9x oh how I will miss you.. :P

Share this post


Link to post
Share on other sites

Woah, looks great!

Nice work here ^^,

AlmarM


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Heh, I'd be honored to have my code included in that, I must admit SMF's a pretty awesome looking tool. I've also been considering someday working with your ShellTriStateTreeView, another awesome program.

Share this post


Link to post
Share on other sites

Updated UDF to support AutoIT v3.3, or UNICODE v3.2.12.1, see 1st post for new code

Share this post


Link to post
Share on other sites

Wow... the speed stats are impressive.. at least for the first run

_WinAPI_FileFind Stats:
Total File count:2072, Total Folder count:52, Time elapsed:823.423088688646 ms
FileFindFile Stats:
Total File count:2072, Total Folder count:52, Time elapsed:2259.5382932747 ms

Second run and so on; I'm getting varied results. Most of the time FileFindFile() is faster your function. :)

_WinAPI_FileFind Stats:
Total File count:2072, Total Folder count:52, Time elapsed:1103.81850207219 ms
FileFindFile Stats:
Total File count:2072, Total Folder count:52, Time elapsed:671.125240777808 ms

a little better...

_WinAPI_FileFind Stats:
Total File count:2072, Total Folder count:52, Time elapsed:867.172224402822 ms
FileFindFile Stats:
Total File count:2072, Total Folder count:52, Time elapsed:688.528849336997 ms

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

Second run and so on; I'm getting varied results. Most of the time FileFindFile() is faster your function. :)

That depends on what you expect to be the return :) , this one not only returns file location info, but at the same time file-attributes, size and times...

Share this post


Link to post
Share on other sites

Wow... the speed stats are impressive.. at least for the first run

...

Second run and so on; I'm getting varied results. Most of the time FileFindFile() is faster your function. :)

...

Kastout, I think I remarked that for getting the attributes and all, _WinAPI_FileFind will always be faster than FileFind.. functions. As for getting just pure filename info, your best bet is the built in FileFind.. functions.

Also, remember, when you are timing how long it takes to read files on a hard drive, the first search will always be the longest, and all subsequent calls will be much faster. That's due to how Windows will buffer the information (though how long the results stay in memory I couldn't say).

The best bet for a clear performance comparison is to reboot Windows between compares. (And don't run them one after the other, but one version on the first clean boot, the other on the 2nd boot)

Also make sure you don't have any other processes actively eating up processor time or accessing the hard drive excessively..

Share this post


Link to post
Share on other sites

Awesome function set, just needed a bump :) ...

Hey, thanks for promoting my UDF ;) You even added it to your sig! Wow, and who gave this UDF 5 stars? Nothing I ever did got stars!! haha.. i feel special now :)

By the way, I've rewritten this UDF so that it can indeed grab the FileTime as a 64-bit number (has to do with structure-alignment), for a little less code and ease of use (and the ability to do some neat manipulations).

Then I went further and made it possible to format the time string in a crapload of ways, to manipulate the FileTime itself (adding/subtracting minutes, hours, days, and so on), and do multiple conversions.

But I digress... all that stuff I'd rather not post here, because this as it stands does just enough and the programmer can choose to modify it at their own leisure.

Anyway, thanks again. Seeya around the forums!

Share this post


Link to post
Share on other sites

is the udf missing?

Yes, the member has left the building and he decided to take his code with him. >_<

This is what he has written in his profile about removing the code:

My apologies to the AutoIT community for removing my posted code. This was done because I knew I would be banned, and I'd rather not have the inability to access, update, and respond to anything related to MY hard work. I hope to move my code over to Google sites, but for now I'm just posting on my blog about the potential future.

For those that want to know about the banning, and my response to the person-responsible's incorrect assertions in this thread, you could visit this blog post. (He specifically said he did not want to discuss things further - which often means 'you'll be banned if you continue', so this is my only recourse)


If you learn from It, it's not a mistake

Share this post


Link to post
Share on other sites

Text and Link to code is now added. Sorry about any inconveniences :(

Share this post


Link to post
Share on other sites

After having this sitting on my PC for a while, I decided to upload the new version. It has the same functioning as it did before, but the FileTime's are now individual array items, and additionally the _WinTimeFunctions module is needed.

UPDATES:

- 5/9/2010: New version with better 64-bit FileTime support, bundled separate example with output display, and the _WinTimeFunctions required module (+ example use). All code falls under the same License agreement! AutoIT v3.3.6+ required.

Share this post


Link to post
Share on other sites

This UDF has been updated! Besides getting rid of the '_WinAPI_' prefix, I've worked on increasing performance with this release, as well as providing Reparse Point information. I'm dedicating this update to KaFu, maker of the fine SMF (Search My Files) program, which includes an older version of this UDF.

Updates:

5/23/2011: New name, faster execution!

* Removed: _WinTimeFunctions UDF. No longer needed (see below).

* Added: New array element for REPARSE Points that are located ($aFind[7]).

* Added: Internal time-conversion function removes the need for _WinTime* calls. This results in a solid increase in performance.

* SCRIPT-BREAKING CHANGES *: Function-names changed - A simple search&replace should work here.

Share this post


Link to post
Share on other sites

I'll definitly incorporate this one into the upcoming v1.6 release of SMF :huh2:, thanks a lot m8, your work is really much appreciated!

Share this post


Link to post
Share on other sites

Ahh! I just looked at your 1.5 source again and realized there will be more script-breaking changes then I listed, since you used an older version which still used 32-bit values instead of 64-bit ones (changed in last year's release). The array will now be indexed/accessed differently for you, so it'll be a little more work to get the indexes correct. Sorry about that, mate!

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

  • Similar Content

    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF
    • DeathChicken
      By DeathChicken
      If possible please add or edit the comments to explain how this works.
       
      ;includes functions from other things
      #include <GDIPlus.au3>
      #include <ScreenCapture.au3>
      ;hotkeys
      HotKeySet("{ESC}", _exit)
      HotKeySet("{F1}", _scan)
      ;global variables
      Global $win_title                    ;name of the window
      Global $area_x                        ;
      Global $area_y                        ;
      Global $area_w                       ;
      Global $area_h                        ;
      Global $cursor                         ;
      Global $rect_file                      ;
      Global $hbmpscreen              ;
      Global $i=  1043                      ;moves the rect
      Global $ii=    378                      ;moves the rect
      Global $x=1044                        ;inner rect offset
      Global $y=501                          ;inner rect offset
      Global $hbmprect                    ;image inside rect
      Global $hscreen                        ;image whole screen
                                         
      _GDIPlus_Startup()                    ;?
      ;display hotkeys on screen
      ToolTip("Press F1 to scan | Press ESC to Exit",0,0)
                                          ;infinite loop to keep prog running
      While 1
          Sleep(100)
      WEnd
      Func _scan()
      ;~ reads your screen area:
      _read()
      ;~ converts screen captured into bmp
      _convert()
      ;~ .  Loads converted bmp to be read
      _loadBMP()
      ;~ compares the bmp of your scanned screen to the actual screen that is being displayed
      _compare()
      EndFunc
                                          ;reads screen
      Func _read()
          $hscreen = _ScreenCapture_CaptureWnd("", WinGetHandle($win_title), $area_x, $area_y, $area_x + $area_w, $area_y + $area_h, $cursor)
      EndFunc
                                          ;converts screen into bmp
      Func _convert()
          _GDIPlus_BitmapCreateFromHBITMAP($hscreen)
      EndFunc
                                          ;loads converted screen
      Func _loadBMP()
      _GDIPlus_BitmapCreateFromFile($rect_file)
      EndFunc
                                          ;compares savedBMP to current screen
      Func _compare()
      ;If(                              below code                                     ) = (                   below code           ) Then
      If _GDIPlus_BitmapGetPixel($hbmpscreen, ($i + $x) - $area_x, ($ii + $y) - $area_y) = _GDIPlus_BitmapGetPixel($hbmprect, $x, $y) Then
      ;display message box titled found with a message of found
      MsgBox("","","found")
      ;if above is not correct then
      EndIf
      EndFunc
                                          ;exit func
      Func _exit()
          Exit
      EndFunc
    • algiuxas
      By algiuxas
      Hello everybody, so I might found a bug in _ArraySearch:
       
      #include <Array.au3> Local $abc[2] = ["b", "b"] $h = "+---------------------------------+" & @CRLF ConsoleWrite($h) For $i = 0 To 1 $abc[0] = 0 out() $abc[0] = 1 out() $abc[0] = -1 out() $abc[0] = "Abc" out() $abc[1] = "Hello" Next Func txt() Return "$abc = [" & $abc[0] & ", " & $abc[1] & "]" & @CRLF & _ "> _ArraySearch($abc,""Hello"") = " EndFunc ;==>txt Func shouldoutput($ans) Return "_ArraySearch Should return: " & ($ans ? 1 : -1) EndFunc ;==>shouldoutput Func out() ConsoleWrite("> " & txt() & _ArraySearch($abc, "Hello") & @CRLF & "> " & shouldoutput($abc[1] == "Hello") & @CRLF & $h) EndFunc ;==>out Exit Sorry for this messy script
    • 9252Survive
      By 9252Survive
      Hi All, 
       
      I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation  (   For $i = 1 To UBound($FileArray) - 1).
      So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on?  Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder?
      Any insight/help will be much appreciated 
    • wakillon
      By wakillon
      Mp3SearchEngine v2.0.0.6

      May be some of you know Songr .
      This script do the same job, it can find more mp3 files but is not as fast as Songr.
       
       



      Sites used are music search engine Websites designed for LEGAL entertainment purposes only.
      Thanks to Brett Francis, Prog@ndy and Eukalyptus for >Bass Udf, trancex for >WinHttp Udf and the AutoIt Community for his help.

       
      Changes of v1.0.8.5
       
      Three websites replaced cause they are dead or use now js.
      All search engines updated ( not without difficulties for audiodump)
      I use RAGrid.dll for the first listview (more fast and stable, but with some inconvenients to manage the no-edit of cells)
      Input queries are saved ( the twenty latest)
      I use now an mp3 pre-Load management before playing and a double progressbar for visualize pre-load and play, where you can click for directly go play in the loaded part.
      Most includes needed are embedded and all external files are embedded in script with >BinaryToAu3Kompressor .
      Multi downloads available with embedded downloader.exe
       
      Changes of v1.0.8.8
      Search on audiodump and myfreemp3 fixed.
      New buttons.
      Added Gui Menu.
      Titles are no more editable.
      New "About" with >TaskDialog (Thanks Prog@andy)
      Query button permit now to check / uncheck all checkboxes
      And some few fixes and cleaning.
      Really more stable now.
      Changes of v1.0.9.2
      Dilandau is replaced by mp3chief and mp3ili by mp3clan 
      Search on mp3juices, baseofmp3 and soundcloud fixed.
      Soso now provide m4a (aac) instead of mp3 ( m4a can be played by MSE)
      Added possibility to encode automaticaly to mp3, aac or ogg ( at the end of download) using bassenc.dll and command line tools : lame, faac and oggenc.
       
      Changes of v1.0.9.3   mp3skull fixed mp3chief fixed myfreemp3 fixed mp3clan changed to tusmp3  mp3juices changed to emp3world baseofmp3 changed to imp3 and some minor improvements.  
      Version 2.0.0.6
      Most previous websites used are dead or have changed the way to get links, 
      so instead of try to repair the previous version, i have created a complete new version.
      The main tendency is the simplification :
      Only one website : audiodump (Up to 500 results by request)
      Script use now the little pearl created by Ward : curl.au3
      It permit to create tasks (get source and get multi mp3) in asynchronous mode.
      So now, no need to use several executables and no more gui who do not respond in case of connection problems. 
      Script use Bass.dll X86 loaded in memory for play songs.
      Result is light and fast, but don't abuse of audiodump servers who are not beasts of race.
      Warning : For avoid errors with curl.au3, you'll need to comment the line 63 : ;~ #Include <BinaryCall.au3>
      @AutoItX64 not supported and only tested on Win7X64 and Win8.1X64.
      As your browser, use Ctrl+w for remove the current Tab.(if there is no search or download running from it)
      And also Ctrl+q for set/remove Gridlines.
      Events are displayed to the bottom of the Gui.
       
      Version 2.0.1.1
      Added a Paste Button.
      Querry list is now correctly saved.
      Querry Combo is now sorted in alphabetical order
      After a 'No match', the next search will use the previous empty listview.
      Bug when removing tabs is corrected.
      Added string correction for the request that, in the previous version, was not always able to return a correct result.
       
      A big thanks to Ward for his great UDF, and Nina my favorite tester, (who between us is also my third daughter), for his precious advices .
      previous downloads : 1703
       
      As there is no more script downloads count, source and executable are available in the downloads section

      Enjoy ! 
      July 2017 Project Discontinued due to website changes