Hey guys,
Just wanted to ask if there is a command that can search for a file and return the path. I don't want the user to enter the path into some requester or something, that's why I'm looking for a command that can do exactly that. Why do I want this? well, after the user has entered some data and clicked on the "Launch" button, I want a to run acertain .exe file. But to do this, I need the path. So, does anyone know how to do this?
Thanks in advance
Find file
Re: Find file
some specific .exe ? Most they use the registry to put some datas in, like installpath etc...
- J@ckWhiteIII
- Enthusiast
- Posts: 183
- Joined: Fri May 25, 2012 7:39 pm
Re: Find file
And how do i get the path from there? i mean...the user could have moved the .exe (for example from the normal directory to the desktop). I need to know how to find a file that could be ANYWHERE on the hard disk
Re: Find file
Maybe something like http://www.purebasic.fr/english/viewtop ... +directory?
Re: Find file
its not pretty but it works:
this will find a file on your hdd called files.txt, starting at root c:\
Code: Select all
Procedure FindPath(Directory$,File$,*mem,Poz)
If ExamineDirectory(Poz, Directory$, "*.*") And PeekS(*mem)=""
While NextDirectoryEntry(Poz)
If DirectoryEntryType(Poz)=#PB_DirectoryEntry_File
If UCase(DirectoryEntryName(Poz))=UCase(file$)
PokeS(*mem,Left(Directory$,4095))
EndIf
Else
If DirectoryEntryName(Poz)<>"." And DirectoryEntryName(Poz)<>".."
FindPath(Directory$+DirectoryEntryName(Poz)+"\",File$,*mem,Poz+1)
EndIf
EndIf
Wend
FinishDirectory(Poz)
EndIf
EndProcedure
*path=AllocateMemory(4096)
FindPath("c:\","Files.txt",*path,0)
MessageRequester("Path","Path= "+PeekS(*path))
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Find file
...you can find an exe file via it's document extension. For example, find PureBasic.exe, extension "pb":
Code: Select all
Procedure.s FindExe(sExt.s)
;--------------------------
;Return the exe path name associated with the given file extension
Protected sDir.s = "C:\"
Protected sDummyFile.s = sDir + "Test." + sExt
Protected sExePath.s = Space(#MAX_PATH)
Protected iResult.i = 0
Protected sErrorMsg.s = "Error Occured"
If CreateFile(0,sDummyFile) : CloseFile(0) : EndIf
iResult = FindExecutable_(@sDummyFile,@sDir,@sExePath)
If Not (iResult > 32)
Select iResult
Case 0 : sErrorMsg = "System out of memory or resource"
Case 31 : sErrorMsg = "There is no association for file type"
Case #ERROR_FILE_NOT_FOUND : sErrorMsg = "File not Found"
Case #ERROR_PATH_NOT_FOUND : sErrorMsg = "File Path not Found"
Case #ERROR_BAD_FORMAT : sErrorMsg = sExePath + " is invalid"
EndSelect
ProcedureReturn(sErrorMsg)
Else
ProcedureReturn(sExePath)
EndIf
DeleteFile(sDummyFile)
EndProcedure
Debug FindExe("pb")
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Find file
Hello,
One more solution here : http://www.purebasic.fr/english/viewtop ... 12&t=50095
The FindFile() command come with an example, see if this can fit your needs.
Best regards.
Guimauve
One more solution here : http://www.purebasic.fr/english/viewtop ... 12&t=50095
The FindFile() command come with an example, see if this can fit your needs.
Best regards.
Guimauve
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Find file
...the FindFile examples on the forum all seem to be terribly slow on Windows. If appropriate for the task in hand, FindExecutable_() is instant.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.