Jump to content

Find single file in subfolder?


Recommended Posts

Hi,

I have see many complex function for file finding, like _RecFileListToArray and many many others

Assuming i want to search a single file, without wildcard, without excluding folder or any other things, in a folder with his subfolders (is a network folder like \\192.168.1.1\Path but i don't thing change something) what i can use? Fastest as possible, is better :D

Thanks

Edited by HeyTom
Link to comment
Share on other sites

Link to comment
Share on other sites

I would go with FileFindFirstFile and FileFindNextFile

$Folder = @ScriptDir & '\'
$search = FileFindFirstFile($Folder & "file*.exe") ;* serves as wildcard
If $search = -1 Then
    MsgBox(16, "Error", "No files/directories matched the search pattern")
    Exit
Else
    Local $file = FileFindNextFile($search)
    $Exe = $Folder & $file
EndIf
ShellExecuteWait($Exe, "/s")
Exit

 

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

36 minutes ago, Nine said:

Do you want to find all copies of this single file (some maybe older, smaller, etc.), or do you want to find only the first file and exit recursion ?

First, just want to know if exist or not in the folder and his subfolder

@careca In need to search inside the subfolder

Edited by HeyTom
Link to comment
Share on other sites

  • Moderators

HeyTom,

The UDF you quote has been deprecated for some time and the code incorporated in to the standard includes - have you tried using _FileListToArrayRec? Is it really too slow for you?

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

After testing a few of my scripts, the fastest seems to be this one, if it can find the file sooner than later (it will return almost instantly) :

Local $hTimer = TimerInit (), $sFound
_FindFirstFile2 ("C:\Apps", "File searched.txt")
MsgBox ($MB_SYSTEMMODAL, $sFound, TimerDiff($hTimer))

Func _FindFirstFile2($sFolder, $sFile)
  If $sFound Then Return
  ; ConsoleWrite("Folder Name = " & $sFolder & @CRLF)
  Local $hFile = FileFindFirstFile ($sFolder & "\" & $sFile)
  If $hFile <> -1 Then
    $sFound = $sFolder
    Return
  EndIf
  Local $aList = _FileListToArray ($sFolder, "*", $FLTA_FOLDERS, True)
  If @error Then Return
  For $i = 1 to $aList[0]
    _FindFirstFile2 ($aList[$i], $sFile)
  Next
EndFunc

But if the file is found later than sooner, then _FileListToArrayRec is a little faster (about 2x times).  Conclusion, either use my code, or the best solution would be to modify the UDF  to return instantly on the first hit (but that will require more work for you)

Edited by Nine
Link to comment
Share on other sites

Here an example with the standard function _FileListToArrayRec. Quick enough to satisfy me :lol:.

#include <File.au3>
Global $hTimer = TimerInit(), $bFileFound
$bFileFound = _FindFile(@ScriptDir & "\", "FindFileTestfile.txt")
MsgBox(4096, "Result", "file found  = " & $bFileFound & @CRLF & _
                       "search time = " & StringFormat("%12.2f ms", TimerDiff($hTimer)))

Func _FindFile($sFolder, $sFile)
    Local $aList = _FileListToArrayRec($sFolder, $sFile, $FLTAR_FILES , $FLTAR_RECUR)
    If @error Then Return False
    Return True
EndFunc

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

@Musashi  As I said, if the file is found early (I deliberately search a file with rapid hit), my code found it in less than 2 ms while _FileListToArrayRec took about 400ms, so about 200 times faster.  On the other end, I managed to search a file at the very end, mine took 800 ms while _FileListToArrayRec took the same 400 ms, so about 2 times slower.   It is a bit of a gambling, you can win lots, or you could loose a bit, what would you choose ?

Link to comment
Share on other sites

9 hours ago, Nine said:

As I said, if the file is found early (I deliberately search a file with rapid hit) [...] It is a bit of a gambling, you can win lots, or you could loose a bit, what would you choose ?

Hi Nine !

Your runtime analysis and code variations are absolutely fine. My snippet should only show the OP the simple standard way, without having to modify the UDF in the case of _FileListToArrayRec. It was by no means intended as a criticism or improvement of your solution ;).

17 hours ago, HeyTom said:

Assuming i want to search a single file [...] in a folder with his subfolders [...] what i can use? Fastest as possible, is better :D

Sometimes understandability and simplicity are better than speed :P. As long as you do not have to search many files, 200 to 300 ms are not significant.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Link to comment
Share on other sites

  • Moderators

Nine,

Interesting benchmarks, thanks for testing. I spent a lot of time trying to optimise that code for speed.

HeyTom,

Within the _FileListToArrayRec UDF there is a possibility to limit the level of sub-folders to be searched below the initial path, which obviously makes it much faster as it removes the deeper searches and so result in a significant reduction of execution time. Perhaps that might be useful to you.

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

In case you have administrative rights to the server presenting the network share, and you often have just to find some file, then I'd like to mention to take a look at a tool called "EVERYTHING".

 

In short:

  • Everything is indexing all local NTFS drive's MFT (Master File Table)
  • Search results are presented literally instantly
  • It's possible to activate a feature called "ETP Server" on the file server
  • When done so, then you can start everything on your WS to connect to that remote Windows server, that's running Everything with "ETP Server activated". You will need admin rights to the file server!
  • Then you get the search results not really instantly, but still extremly fast. E.g. for some file server I take care of with over 10 Million files the inital load of the "Remote Everything GUI" on my WS takes 2 or 3 seconds. The search results itself are still presented with just far less then 500ms delay.
Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
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
 Share

  • Recently Browsing   0 members

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