Jump to content

Recommended Posts

Posted (edited)

I don't know where I originally found this function, but when I had it, it consisted of a complex jump between 2 functions, now its just one and its perfect for noobs looking for a file searching function.

Edit: Obsolete, take a look at Melba32's mod'd version for a script thats 20x faster Posted Image

ScanFolder(@WindowsDir,"HelpPane.exe,Explorer.exe,Notepad.exe")

Func ScanFolder($SourceFolder,$46)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath
    Local $FileCount = 0
    $Search = FileFindFirstFile($SourceFolder & "\*.*")
    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)
        If StringInStr($FileAttributes,"D") Then
            ScanFolder($FullFilePath,$46)
        Else
    $460 = StringSplit($FullFilePath,",")
    $461 = UBound($460) - 1

    ToolTip($FullFilePath,0,0)
    If StringInstr($46,$460[$461]) then
    MsgBox(0,"Done","MATCH!! " & $460[$461])
    EndIf
        EndIf
    WEnd
    FileClose($Search)
EndFunc

this should make it a lot easier for noobs to locate a file with autoit, very easy to include in your script.

not that I'm not a newbie myself....

Edited by System238
Posted (edited)

Maybe here >> or :)

But this is the first instance of it appearing with the name ScanFolder and similar syntax >>

I thought it best you know, sorry. Nice function though, might have some use for one day. (Haven't Tested!)

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

  • Moderators
Posted

System238,

Have you actually tried running that code? :) I think not, because it simply does not work!

Take a look at this modified version (which does :idiot:) and try and work out why the differences make such a difference. :idiot:

ScanFolder(@WindowsDir,"HelpPane.exe,Explorer.exe,Notepad.exe")

Func ScanFolder($SourceFolder, $46)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath
    Local $FileCount = 0
    $Search = FileFindFirstFile($SourceFolder & "\*.*")
    If $Search = -1 Then Return
    While 1
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        If @extended Then ; This is much faster than looking for the "D" attribute
            ScanFolder($SourceFolder & "\" & $File, $46)
        Else
            $460 = StringSplit($SourceFolder & "\" & $File, "\") ; If you split on "," you do NOT get the file name in $460[461]
            $461 = UBound($460) - 1
            ;ToolTip($FullFilePath, 0, 0)
            If StringInStr($46, $460[$461]) Then
                MsgBox(0, "Done", "MATCH!! " & $SourceFolder & "\" & $File)
            EndIf
        EndIf
    WEnd
    FileClose($Search)
EndFunc   ;==>ScanFolder

Please take this as constructive criticism. ;)

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

 

Posted (edited)

it works on my pc, im using virtual box with win 7 running in it...

Edit: lol, your version is like 20x faster.Posted Image

Now I see why, the tool tip is slowing it down a whole lot and removing it improves speed dramatically along with The "@extended" macro you added.

Thanks! I had no idea how that worked at first..

ScanFolder(@WindowsDir,"HelpPane.exe,Explorer.exe,Notepad.exe")

Func ScanFolder($SourceFolder, $46)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath
    Local $FileCount = 0
    $Search = FileFindFirstFile($SourceFolder & "\*.*")
    If $Search = -1 Then Return
    While 1
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        If @extended Then ; This is much faster than looking for the "D" attribute
            ScanFolder($SourceFolder & "\" & $File, $46)
        Else
            $460 = StringSplit($SourceFolder & "\" & $File, "\") ; If you split on "," you do NOT get the file name in $460[461]
            $461 = UBound($460) - 1
            ;ToolTip($SourceFolder & "\" & $File, 0, 0)
            If StringInStr($46, $460[$461]) Then
                MsgBox(0, "Done", "MATCH!! " & $SourceFolder & "\" & $File)
            EndIf
        EndIf
    WEnd
    FileClose($Search)
EndFunc

In example, I've enabled the tool tip again in your modified version and its about 5x slower than without it.

Edited by System238
  • Moderators
Posted

System238,

it works on my pc

Then I am extremely surprised. :idiot:

Look at this part of your code:

$460 = StringSplit($FullFilePath,",")
    $461 = UBound($460) - 1

     ToolTip($FullFilePath,0,0)
    If StringInstr($46,$460[$461]) then

You are splitting the path on "," which does not normally feature in a full path. So you are most likely to get the following array:

[0] 1
[1] whatever $FullFilePath was

as StringSplit returns an error. So $460[$461] will be the full path which will never match with the contents of the $46 variable. That is why I said it does not work - certainly it does not work on my machine.

Try adding a line like this to your original script just before the ToolTip line and see what you get as a value:

ConsoleWrite($460[$461] & @CRLF)

I get the full path of every file scanned - best not do this on the Windows folder by the way , it takes a long time to print them all! :idiot:

If you split the path using "\" then you are going to get the file name in the final element of the $460 array and you will get a match if it exists when using StringInStr with the passed list. :)

Again, please do not think I am being picky - but I really do not see how the original can work. ;)

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

 

Posted (edited)

System238,

Then I am extremely surprised. :)

Look at this part of your code:

$460 = StringSplit($FullFilePath,",")
    $461 = UBound($460) - 1

    ToolTip($FullFilePath,0,0)
    If StringInstr($46,$460[$461]) then

M23

$460 = StringSplit($FullFilePath,",")

Is splitting line

[color=#008080][font=monospace][size=2]"HelpPane.exe,Explorer.exe,Notepad.exe"[/size][/font][/color]

to search for a match. so thats why it works on my machine but it does take a long time as you said.

Yes, I was wrong...

any way, now that I'm here, I was wondering.

How do I search for a file name match consisting of only part of the file name?

I,e - search for all files that begin with "lol", and resulting matches would be "lol1.png" & "lolueb.exe"

Edited by System238
  • Moderators
Posted

System238,

I wondered if you might have thought you were running the StringInStr the other way round - but then you would only ever have checked the final filename in your checking list. ;)

How do I search for a file name match consisting of only part of their name?

Take a look at the RecFileListToArray UDF in my sig and you will see how you might match partial names using StringRegExp. Warning: the code does get a bit complex - especially the SRE part - although I have commented it liberally. :)

If you have any questions about any aspect of the UDF then start a new topic in "General Help" and we can discuss it there rather than clog up the "Examples" section. :idiot:

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

 

Posted (edited)

Have a look here >> Though M23 will probably have something better, plus there is their UDF's to have a look at!

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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
×
×
  • Create New...