(Related to viewtopic.php?f=13&t=77993)
How can I detect the existence of a file / program (such as 'notepad.exe' if it IS included in (Windows') search path, but I do NOT know the exact location?
Check if a file exists somewhere in the path
Check if a file exists somewhere in the path
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Check if a file exists somewhere in the path
You can parse the environment variable "PATH" and check all the path with your exe.
Re: Check if a file exists somewhere in the path
Yeah, I considered that option... I may have to do that...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- User
- Posts: 92
- Joined: Sun Oct 24, 2004 9:25 am
Re: Check if a file exists somewhere in the path
Not too demanding, since the filename is already known. No need for the "ExamineDirectory" chore
Code: Select all
EnableExplicit
Define SoughtAfterFile$ = "Notepad.exe"
Define EPath$ = GetEnvironmentVariable("PATH")
Define Flag = 0
Define i = 1
Define SPath$ = StringField( EPath$, i, ";" )
Repeat
; Debug SPath$
If FileSize( SPath$+"\" + SoughtAfterFile$ ) > -1
Flag = #True
Break
EndIf
i + 1
SPath$ = StringField( EPath$, i, ";")
Until SPath$ = ""
If flag
Debug "FQFN of " + SoughtAfterFile$ + " is " + SPath$+"\"+SoughtAfterFile$
Else
Debug SoughtAfterFile$ + " not in Path(s) "
EndIf
Is this an artifact or should it be disposed of ?
Re: Check if a file exists somewhere in the path
where (= 'which' on un*x)
where where
C:\Windows\System32\where.exe
Code: Select all
C:\>where notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
C:\Windows\System32\where.exe
Code: Select all
Compiler = RunProgram("where", "notepad", "", #PB_Program_Open | #PB_Program_Read)
Output$ = ""
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Output$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
Output$ + Chr(13) + "Exitcode: " + Str(ProgramExitCode(Compiler))
CloseProgram(Compiler)
EndIf
MessageRequester("Output", Output$)
-
- User
- Posts: 92
- Joined: Sun Oct 24, 2004 9:25 am
Re: Check if a file exists somewhere in the path
@ Marc56us
He just might also be looking for .ddl-, .lib- and other files not executable on their own .
He just might also be looking for .ddl-, .lib- and other files not executable on their own .
Is this an artifact or should it be disposed of ?
Re: Check if a file exists somewhere in the path
Thx for the replies, in this specific case I was indeed looking for .exe, .lnk, and .bat., but mostly I was trying to avoid errors when calling stuff without a full specified path, such as 'notepad.exe'.
This was triggered by a little problem I had with RunProgram().
I got it working now. Thx!
(Oh, just re-read. No, I am NOT trying to write bad stuff!)
This was triggered by a little problem I had with RunProgram().
I got it working now. Thx!
(Oh, just re-read. No, I am NOT trying to write bad stuff!)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )