Jump to content
Sign in to follow this  
Davy123

Search folder - (Moved)

Recommended Posts

Hello, I have on my D drive a lot of folders like: 190021, 190025, 190097, all those folders are in different subfolders. So I want a script If I put in the folder name: 190021, that it search in the subfolders for this, and after open in.

Can any one help me?

 

 

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

folder()
Func folder()

    ; Asks the user to enter a password.  Don't forget to validate it!
     Local $foldername = InputBox("Folder search", "Give folder name", "")
     If $foldername > 1 Then

;==> search folder name like: 190027 in 😧 and subfolders
   
 EndIf
 Exit
 EndFunc   ;==>Example
 

Share this post


Link to post
Share on other sites

You know that Windows Explorer does this in the search bar, right? I'm not sure why you'd need a script to do this... maybe there's more you're looking for?


All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites
19 hours ago, seadoggie01 said:

You know that Windows Explorer does this in the search bar, right? I'm not sure why you'd need a script to do this... maybe there's more you're looking for?

We have already a script for new order folders, and new customers, so it would be nice if we can give in the order number (what the name is of the folder), and then it open automatic. 

Share this post


Link to post
Share on other sites

I'm not sure exactly what you're looking for, but here's a function I made that takes a path and an array and gets all files in the root folder and subfolders...

#include <Array.au3>
Local $files[0]

RecursiveSearch(@Desktop & "\*", $files)
_ArrayDisplay($files)

Func RecursiveSearch($folder, ByRef $array)
    Local $search = FileFindFirstFile($folder)
    If $search <> -1 Then
        Local $name = FileFindNextFile($search)
        ; "While the name isn't blank"
        While $name <> ""
            If @error Then
                ConsoleWrite("! Error: " & @error & " Found last file with FileFindNextFile")
            ElseIf @extended = 0 Then
                ; "Keep the file"
                _ArrayAdd($array, StringReplace($folder, "*", $name))
            Else
                ; "It's a folder, search it too!"
                RecursiveSearch(StringReplace($folder, "*", $name & "\*"), $array)
            EndIf
            ; "Get the next item"
            $name = FileFindNextFile($search)
        WEnd
    EndIf
EndFunc

I hope this helps :)

Edited by seadoggie01
Removing undeclared function

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites

@Davy123, maybe you can play with this (just change the progress bar if you want😅 or change some of it if you like). Credit from Deye👍...

 

#include <File.au3>
#include <String.au3>
#include <GUIConstantsEx.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <GuiListView.au3>

$aArray = DriveGetDrive("ALL")
For $i = 1 To $aArray[0]
    $aArray[$i] = StringUpper($aArray[$i])
Next
$sString = _ArrayToString($aArray, "|", 1)

$hGUI = GUICreate("SearchMe", 310, 300)

$hCombo = GUICtrlCreateCombo("---", 10, 10, 40, 20) ;File*.mp3
GUICtrlSetFont(-1, 12)
GUICtrlSetData(-1, $sString)
$input = GUICtrlCreateInput("", 52, 10, 160, 25)
GUICtrlSetFont($input, "12")
$Button = GUICtrlCreateButton("Search", 215, 9, 88, 25)
$File = GUICtrlCreateRadio("File", 60, 35, 60, 25)
GUICtrlSetState($File, $GUI_ENABLE)
$Folder = GUICtrlCreateRadio("Folder", 130, 35, 60, 25)
GUICtrlSetState($Folder, $GUI_ENABLE)
$Progress = GUICtrlCreateProgress(10, 60, 290, 20)
$label = GUICtrlCreateLabel("Progress search folder here ie. D:\Folder1\Folder2\...", 10, 82, 350, 26)
$ListView1 = GUICtrlCreateListView("Count|Path                  ", 10, 110, 290, 180)
$idItem = GUICtrlCreateListViewItem("", $ListView1)
GUISetState()
$sFilePath = @ScriptDir & "\Drive.txt"
Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND)

Local $iWait = 20; wait 20ms for next progressstep
Local $iSavPos = 0; progressbar-saveposition


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $File
         MsgBox(64,"Pending","Don't use me!")
         GUICtrlSetState($File, $GUI_UNCHECKED)
         GUICtrlSetState($Folder, $GUI_CHECKED)
         GUICtrlSetState($File, $GUI_DISABLE)
        Case $Button
            If  GUICtrlRead($File) = $GUI_CHECKED Then
               MsgBox(64,"Opss","No Code Yet")
               GUICtrlSetState($Folder, $GUI_DISABLE)
            ElseIf GUICtrlRead($Folder) = $GUI_CHECKED Then
               GUICtrlSetState($File, $GUI_DISABLE)
               FileWrite($hFileOpen, _Search(GUICtrlRead($hCombo)&GUICtrlRead($input), Default, 7) & @CRLF)
               GUICtrlSetData($idItem, "|"&_Search(GUICtrlRead($hCombo)&GUICtrlRead($input), Default, 7))
               GUICtrlSetState($Button, $GUI_ENABLE)
               GUICtrlSetState($input, $GUI_ENABLE)
               GUICtrlSetState($hCombo, $GUI_ENABLE)
               GUICtrlSetData($Progress, "100%")
               GUICtrlSetData($label, "Searched Completed 100%...")
            EndIf
    EndSwitch
WEnd
Func DriveSearch()
   Const $sFolder = GUICtrlRead($input)
   Local $aDrives = GUICtrlRead($hCombo)
   MsgBox(64,"Info",$aDrives)
   If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Unable to get drives")
   Local $aFolder, $aListFolders[0]
      GUICtrlSetData($Progress, "50%")
      $aFolder = _FileListToArrayRec (StringUpper($aDrives) & "\", $sFolder, $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
      GUICtrlSetData($label, $aFolder)
      GUICtrlSetData($label, $aListFolders)
      _ArrayDelete ($aFolder, 0)
      _ArrayAdd ($aListFolders, $aFolder)
      _ArrayDisplay ($aListFolders)
      GUICtrlSetData($ListView1, _ArrayAdd ($aListFolders, $aFolder))
      GUICtrlSetData($Progress, "100%")
   GUICtrlSetState($Folder, $GUI_ENABLE)
EndFunc

Func _Search($sSearch, $iStartLevel = 1, $iEndLevel = 7) ; $iLevel folders levels deeep
    GUICtrlSetState($Button, $GUI_DISABLE)
    GUICtrlSetState($input, $GUI_DISABLE)
    GUICtrlSetState($hCombo, $GUI_DISABLE)
    GUICtrlSetData($Progress, "20%")
    GUICtrlSetData($Progress, "40%")
    GUICtrlSetData($Progress, "50%")
    GUICtrlSetData($Progress, "80%")
    Local $a = StringSplit($sSearch, ":"), $Ret = _GetAppropriatePath($a[1] & ":\*" & $a[2] & "*")
    If $Ret Then Return $Ret
    GUICtrlSetData($Progress, "20%")
    GUICtrlSetData($Progress, "40%")
    GUICtrlSetData($Progress, "50%")
    GUICtrlSetData($Progress, "80%")
    For $i = $iStartLevel To $iEndLevel
        $Ret = _GetAppropriatePath($a[1] & ":\*" & _StringRepeat("\*", $i) & $a[2] & "*")
        If $Ret Then Return $Ret
        GUICtrlSetData($idItem, $i)
    Next
    Return ""
EndFunc   ;==>_Search

Func _GetAppropriatePath($sPath, $iLevel = 0)
    Local $hSearch, $tPath, $Folder, $Item, $Path, $Ret, $Dir = '', $Suf = '', $Result = ''

    $tPath = DllStructCreate('wchar[1024]')
    $Ret = DllCall('kernel32.dll', 'dword', 'GetFullPathNameW', 'wstr', $sPath, 'dword', 1024, 'ptr', DllStructGetPtr($tPath), 'ptr', 0)
    If (@error) Or (Not $Ret[0]) Then
        Return ''
    EndIf
    $sPath = DllStructGetData($tPath, 1)
    If StringRight($sPath, 1) = '\' Then
        $Dir = '\'
    EndIf
    $Item = StringSplit(StringRegExpReplace($sPath, '\\\Z', ''), '\')
    Select
        Case $iLevel + 1 = $Item[0]
            If FileExists($sPath) Then
                Return $sPath
            Else
                Return ''
            EndIf
        Case $iLevel + 1 > $Item[0]
            Return ''
    EndSelect
    For $i = 1 To $iLevel + 1
        $Result &= $Item[$i] & '\'
    Next
    $Result = StringRegExpReplace($Result, '\\\Z', '')
    If Not FileExists($Result) Then
        Return ''
    EndIf
    $hSearch = FileFindFirstFile($Result & '\*')
    If $hSearch = -1 Then
        Return ''
    EndIf
    For $i = $iLevel + 3 To $Item[0]
        $Suf &= '\' & $Item[$i]
    Next
    While 1
        $Folder = FileFindNextFile($hSearch)
        If @error Then
            $Result = ''
            ExitLoop
        EndIf
        If (Not @extended) And ($Dir) And ($iLevel + 2 = $Item[0]) Then
            ContinueLoop
        EndIf
        $Ret = DllCall('shlwapi.dll', 'int', 'PathMatchSpecW', 'wstr', $Folder, 'wstr', $Item[$iLevel + 2])
        If (Not @error) And ($Ret[0]) Then
            $Path = _GetAppropriatePath($Result & '\' & $Folder & $Suf & $Dir, $iLevel + 1)
            If $Path Then
                $Result = $Path
                GUICtrlSetData($label, $Result)
                ExitLoop
            EndIf
         EndIf
         GUICtrlSetData($label, $Result)
         GUICtrlSetData($Progress, "90%")
    WEnd
    FileClose($hSearch)
    Return $Result
EndFunc

 


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites

Try this :

#include <File.au3>

Opt ("MustDeclareVars", 1)

Local $sDrive = "D:\"

Local $foldername = InputBox("Folder search", "Give folder name")
If @error Then Exit
Local $aFolder = _FileListToArrayRec ($sDrive, $foldername, $FLTAR_FOLDERS, $FLTAR_RECUR, Default, $FLTAR_FULLPATH)
_ArrayDisplay ($aFolder)
If $aFolder[0] Then ShellExecute ($aFolder[1])

 

Share this post


Link to post
Share on other sites
On 8/30/2019 at 11:00 AM, Nine said:

Try this :

#include <File.au3>

Opt ("MustDeclareVars", 1)

Local $sDrive = "D:\"

Local $foldername = InputBox("Folder search", "Give folder name")
If @error Then Exit
Local $aFolder = _FileListToArrayRec ($sDrive, $foldername, $FLTAR_FOLDERS, $FLTAR_RECUR, Default, $FLTAR_FULLPATH)
_ArrayDisplay ($aFolder)
If $aFolder[0] Then ShellExecute ($aFolder[1])

 

This works, but it search only in the main folder, and not in the sub folders.

Share this post


Link to post
Share on other sites

Davy123,

That script works perfectly for me - it finds and then opens the named folders well down within the tree structure.

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

 

Share this post


Link to post
Share on other sites

Davy, the flag $FLTAR_RECUR tells the function to be recursive. So it goes down all the way. Out of curiosity, what did you enter in the input box ? 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...