jimanny Posted May 15, 2008 Share Posted May 15, 2008 In DOS, this works to get the full path to a file that's in the system path: for %a in ("somefile.txt") do echo %~$PATH:a Is there an AutoIt function that does this or do I just use Run( @COMSPEC ... ). Thanks. Link to comment Share on other sites More sharing options...
sandin Posted May 15, 2008 Share Posted May 15, 2008 $file = "regedit.exe" $full_path = @SystemDir & "\" & $file MsgBox(0, "ok", $full_path) Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 15, 2008 Share Posted May 15, 2008 In DOS, this works to get the full path to a file that's in the system path: for %a in ("somefile.txt") do echo %~$PATH:a Is there an AutoIt function that does this or do I just use Run( @COMSPEC ... ). Thanks. Either FileOpen() and then a loop of FileReadLine()s, or _FileReadToArray() and loop through the array. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jimanny Posted May 15, 2008 Author Share Posted May 15, 2008 Thanks for the replies. $file = "regedit.exe" $full_path = @SystemDir & "\" & $file MsgBox(0, "ok", $full_path) I don't know in advance where "somefile.txt" lives or if it even exists. It may not be in @SystemDir. Either FileOpen() and then a loop of FileReadLine()s, or _FileReadToArray() and loop through the array. I'm looking for the file's path. I think FileOpen() and FileReadLine() are for reading the file. Link to comment Share on other sites More sharing options...
jimanny Posted May 15, 2008 Author Share Posted May 15, 2008 (edited) This seems to do the trick: Dim $filePath = GetPathToFileInSystemPath( "SomeFileInSystemPath.txt" ) ConsoleWrite( "Path to file = " & $filePath ) Func GetPathToFileInSystemPath( $fileName ) Local $process = Run( @ComSpec & ' /c for %a in ("' & $fileName & '") do echo %~$PATH:a', @ScriptDir, @SW_HIDE, $STDOUT_CHILD ) Local $filePath While 1 $line = StdoutRead($process) If @error Then ExitLoop If $line = "" Then ContinueLoop $filePath = $line WEnd return $filePath EndFunc Edited May 15, 2008 by jimanny Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 15, 2008 Share Posted May 15, 2008 Well, you might go with this: #include <Array.au3>; Only for _ArrayDisplay() Global $sFileName = "notepad.exe" Global $avResults = _FileFindInPath($sFileName) _ArrayDisplay($avResults, "Results for: " & $sFileName) Func _FileFindInPath($sFile) Local $sRET = "", $avRET[1] = [0] Local $avPath = StringSplit(EnvGet("PATH"), ";") For $n = 1 To $avPath[0] If StringRight($avPath[$n], 1) = "\" Then $avPath[$n] = StringTrimRight($avPath[$n], 1) If FileExists($avPath[$n] & "\" & $sFile) Then $sRET &= $avPath[$n] & ";" Next If StringLen($sRET) <> 0 Then $avRET = StringSplit(StringTrimRight($sRET, 1), ";") Return $avRET EndFunc ;==>_FileFindInPath This version accepts wildcards. Try changing $sFileName = "*.exe". Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jimanny Posted May 15, 2008 Author Share Posted May 15, 2008 PsaltyDS, this is very nice, thanks! 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