Davy123 Posted August 28, 2019 Share Posted August 28, 2019 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 Link to comment Share on other sites More sharing options...
Developers Jos Posted August 28, 2019 Developers Share Posted August 28, 2019 Moved to the appropriate forum. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 28, 2019 Share Posted August 28, 2019 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Davy123 Posted August 29, 2019 Author Share Posted August 29, 2019 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. Link to comment Share on other sites More sharing options...
seadoggie01 Posted August 29, 2019 Share Posted August 29, 2019 (edited) 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 August 29, 2019 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
KickStarter15 Posted August 30, 2019 Share Posted August 30, 2019 @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👍... expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Nine Posted August 30, 2019 Share Posted August 30, 2019 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]) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Davy123 Posted September 5, 2019 Author Share Posted September 5, 2019 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 5, 2019 Moderators Share Posted September 5, 2019 Davy123, That script works perfectly for me - it finds and then opens the named folders well down within the tree structure. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Nine Posted September 5, 2019 Share Posted September 5, 2019 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 ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now