ReadFile the good file

Just starting out? Need help? Post your questions and find answers here.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

ReadFile the good file

Post by SPH »

hi,
in a software developed in PB (obviously), I say this:

Code: Select all

ReadFile(7, "f:\tmp\000.txt")
But I would like to find the file "000.txt" where my EXE is and not at the hard path.
What magic instruction do you suggest?

Thx :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: ReadFile the good file

Post by matalog »

GetCurrentDirectory() will return the directory that the .exe is held in.

Code: Select all

fold$= GetCurrentDirectory()
file$= "000.txt"
Debug fold$+file$
Readfile(7,fold$+file$)
Or depending on how you are using the program, you may want to:

Code: Select all

   
     Temp$ = ProgramParameter()
    SetCurrentDirectory(GetPathPart(temp$))

  
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: ReadFile the good file

Post by Kiffi »

matalog wrote: Tue Jan 21, 2025 12:36 pm GetCurrentDirectory() will return the directory that the .exe is held in.
No!

better use:

Code: Select all

GetPathPart(ProgramFilename())
Hygge
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Re: ReadFile the good file

Post by SPH »

Big Thx To You !!

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: ReadFile the good file

Post by matalog »

Kiffi wrote: Tue Jan 21, 2025 12:50 pm
matalog wrote: Tue Jan 21, 2025 12:36 pm GetCurrentDirectory() will return the directory that the .exe is held in.
No!

better use:

Code: Select all

GetPathPart(ProgramFilename())
Yes. This is a better answer :-).
Post Reply