enigmafyv Posted June 13, 2007 Posted June 13, 2007 Would anyone know how to display the path of a file when searching for it? So let's say I'm looking for a file located two folders deep, but I don't know where it's at, I just know the name of the file. I know this is probably all wrong but here's my conceptual idea: $var = FileFindFirstFile ( "filename" ) Show me the path of $var anyone? -I'm trying to locate a program that might be on any machine by it's exe filename. -Then I want to find out it's parent folder. -I know the program files exist in side of "C:\Program Files". -Now that I've found out where it's at, I want to locate within the Parent folder and all of it's subfolders the uninstall file, usually named "unin000.exe" -Now that the "unin000.exe" is located, execute it.
MrCreatoR Posted June 13, 2007 Posted June 13, 2007 how to display the path of a file when searching for it?Here is example on search file with displaying: expandcollapse popupOpt("GuiOnEventMode", 1) Global $Progress = 0.1 $PathForSearch = @ProgramFilesDir $FileToFind = "FileName.exe" $Gui = GUICreate("File Finder", 300, 170, -1, -1, -1, 0x00000088) GUISetOnEvent(-3, "ExitScript") GUICtrlCreateLabel("Path to search on:", 20, 30) $PathInput = GUICtrlCreateInput($PathForSearch, 20, 50, 270) GUICtrlCreateLabel("File to find:", 20, 90) $FileNameInput = GUICtrlCreateInput($FileToFind, 20, 110, 270) $SearchButton = GUICtrlCreateButton("Search", 70, 140, 60, 20) GUICtrlSetOnEvent(-1, "SearchButton") $CancelButton = GUICtrlCreateButton("Cancel", 180, 140, 60, 20) GUICtrlSetOnEvent(-1, "ExitScript") GUISetState() While 1 Sleep(100) WEnd Func _FindFile($Path, $FileName) If Not IsDeclared("GetPath") Then $GetPath = 0 $ModPath = $Path & "\*" $File = FileFindFirstFile($ModPath) While 1 If $GetPath <> 0 Then ExitLoop $Get = FileFindNextFile($File) If @error Then ExitLoop $String = $Path & "\" & $Get ProgressSet($Progress, $Path & @CR & $Get) $Progress = $Progress + 0.1 If $Progress >= 100 Then $Progress = 0.1 If Not StringInStr(FileGetAttrib($String), "D") Then If $Get = $FileName Then $GetPath = $Path ExitLoop EndIf Else _FindFile($String, $FileName) EndIf WEnd FileClose($File) Return $GetPath EndFunc Func SearchButton() If Not FileExists(GUICtrlRead($PathInput)) Then _MsgBox(16, "Error", "You must type an existing path", $Gui) ElseIf StringRight(GUICtrlRead($PathInput), 1) = "\" Then _MsgBox(48, "Attention!", "The path must not have a slash (\) at the end of it.", $Gui) ElseIf GUICtrlRead($FileNameInput) = "" Then _MsgBox(16, "Error", "You must type a file name", $Gui) ElseIf Not _IsFileName(GUICtrlRead($FileNameInput)) Then _MsgBox(16, 'Error', 'The file name include an invalid characters' & @CR & '< > | ? : * / \ "', $Gui) Else $PathForSearch = GUICtrlRead($PathInput) $FileToFind = GUICtrlRead($FileNameInput) GUISetState(@SW_HIDE, $Gui) ProgressOn("Please wait...", "Search is in progress...", $PathForSearch, -1, -1, 16) $SearchResults = _FindFile($PathForSearch, $FileToFind) ProgressOff() If Not $SearchResults = 0 Then MsgBox(262144+64, "Done!", "File <" & $FileToFind & "> was found in this path <" & $SearchResults & ">.") Else MsgBox(262144+48, "Attention!", "File <" & $FileToFind & "> was not found on <" & $PathForSearch & "> and it subfolders." & @CR & @CR & "OK ---> EXIT") EndIf GUISetState(@SW_SHOW, $Gui) EndIf EndFunc Func _IsFileName($Test) If StringRegExp($Test, '[<>|?:"*/\\]') <> 0 Then Return False Else Return True EndIf EndFunc Func _MsgBox ($MsgBoxType, $MsgBoxTitle, $MsgBoxText, $mainGUI=0) $ret = DllCall ("user32.dll", "int", "MessageBox", _ "hwnd", $mainGUI, _ "str", $MsgBoxText , _ "str", $MsgBoxTitle, _ "int", $MsgBoxType) Return $ret [0] EndFunc Func ExitScript() Exit EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
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