How to find the folder of your file location
How to find the folder of your file location
Hello ,
Hope someone can enlighten me on how I can solve this problem.
I need to know the folder location where the purebasic exe file is running .
For example, I click a purebasic exe, it runs. I need to know the folder location where it runs from, so that I can copy the entire contents(files and folder) of the folder to another location.
This folder can be anywhere. It can be in a USB drive having any characaters like f: or h: etc or from the computer itself like c:\visless .
I used the following...
Result = CopyDirectory("xxx","c:\11f","*.*",#PB_FileSystem_Recursive)
What should I use to replace the xxx ?
so that all the contents in the current folder where the exe is, cab be transferred to c:\11f folder?
In normal DOS command mode I simply used under batch .bat mode
xcopy *.*/s/i C:\11f> nul
and everything including sub directories are copied to the other folder
Regards
Alan
Hope someone can enlighten me on how I can solve this problem.
I need to know the folder location where the purebasic exe file is running .
For example, I click a purebasic exe, it runs. I need to know the folder location where it runs from, so that I can copy the entire contents(files and folder) of the folder to another location.
This folder can be anywhere. It can be in a USB drive having any characaters like f: or h: etc or from the computer itself like c:\visless .
I used the following...
Result = CopyDirectory("xxx","c:\11f","*.*",#PB_FileSystem_Recursive)
What should I use to replace the xxx ?
so that all the contents in the current folder where the exe is, cab be transferred to c:\11f folder?
In normal DOS command mode I simply used under batch .bat mode
xcopy *.*/s/i C:\11f> nul
and everything including sub directories are copied to the other folder
Regards
Alan
Re: How to find the folder of your file location
Hi Alan,
did you tried GetCurrentDirectory() ?
Bernd
did you tried GetCurrentDirectory() ?
Bernd
Re: How to find the folder of your file location
Thanks Bernd,
you r a gem...
you just saved me lots of unnecessary codings....
(am still wondering how I missed this when I searched under "directory". )
Yes, it works. Well still new to most of purebasic syntax( just registered for purebasic. :>) )
This site is wonderful. Support is just great.
Thanks for the quick response.
Worth every penny I paid for.
Rgds
Alan
you r a gem...
you just saved me lots of unnecessary codings....
(am still wondering how I missed this when I searched under "directory". )
Yes, it works. Well still new to most of purebasic syntax( just registered for purebasic. :>) )
This site is wonderful. Support is just great.
Thanks for the quick response.
Worth every penny I paid for.
Rgds
Alan
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: How to find the folder of your file location
GetCurrentDirectory is not sufficent 
it will carry the directory of the CALLING process if none is specified with the call.
so it often is NOT the directory your exe file is in.
gosh, it was told over and over and over a thousand times since years, does anyone ever read the forums, or do they all just come here to ask questions?
the function you're looking for is
ProgramFilename()
PS
for the record: I'm in a really good mood, not that anyone confuse expressive words with bad mood.

it will carry the directory of the CALLING process if none is specified with the call.
so it often is NOT the directory your exe file is in.
gosh, it was told over and over and over a thousand times since years, does anyone ever read the forums, or do they all just come here to ask questions?
the function you're looking for is
ProgramFilename()
PS
for the record: I'm in a really good mood, not that anyone confuse expressive words with bad mood.
oh... and have a nice day.
-
- Addict
- Posts: 1264
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Re: How to find the folder of your file location
Yes, I'd say ProgramFilename() and then GetPathPart().
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Re: How to find the folder of your file location
@Kaeru Gaman,
hey, why did you shout so loud ?
Why should I search in the forum, when I found a solution in the helpfile, which is/was working for me
Or should I search the forum for every command I use?
I only look arround in the forum if I didn't find a command, or when it fails.
And when this stuff is discussed since years, why is this behaviour not noticed in the current helpfile?
For you, who only looks in the forum:
If you get rid of so 'stupid' answers like mine, than add a topic in the bug section where errors in the
helpfile are placed.
@Alan
So the gurus mean use:to be on the safe side.
Best regards,
Bernd
hey, why did you shout so loud ?
Why should I search in the forum, when I found a solution in the helpfile, which is/was working for me



Or should I search the forum for every command I use?
I only look arround in the forum if I didn't find a command, or when it fails.
And when this stuff is discussed since years, why is this behaviour not noticed in the current helpfile?
For you, who only looks in the forum:
English:Gibt den aktuellen Verzeichnis-Namen zurück.
Nothing more.Returns the current directory name.
If you get rid of so 'stupid' answers like mine, than add a topic in the bug section where errors in the
helpfile are placed.
@Alan
So the gurus mean use:
Code: Select all
GetPathPart(ProgramFilename())
Best regards,
Bernd
-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: How to find the folder of your file location
Because you're misunderstanding the help file, which is what Kaeru is trying to explain to you! The so-called solution you found is just luck for the times you used it. GetCurrentDirectory() returns the current directory, yes. So the help file is 100% correct and does NOT need fixing, and nor does it need any further clarification. BUT, you're just ASSUMING that the current directory is always the same as the EXECUTABLE DIRECTORY, but it isn't. Just because it has been the same path most times doesn't mean it always will be.infratec wrote:Why should I search in the forum, when I found a solution in the helpfile, which is/was working for me![]()
![]()
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: How to find the folder of your file location
the description perfectly right. it returns the name of the current directory. not more, not less.
but most people seem to think, the "current" directory automatically is the directory "where your currently running program file is located".
that is definitely not the case, and if it is, it's most times caused by the "execute in folder" property of the shortcut for the exe.
people who casually read in the forums, even topics not related to their special interests, should have heard it meanwhile, because, as I said, it was told very often.
Alan asked for "the folder of your file location", not for "the current folder", why your answer obviously was wrong.
sorry Bernd.
the problem is, if people search for this task, they may not see my posting if I did not post it large-bold, and take the wrong solution.
every case of this will lead to another "why does my stuff not load"-thread later on.
but most people seem to think, the "current" directory automatically is the directory "where your currently running program file is located".
that is definitely not the case, and if it is, it's most times caused by the "execute in folder" property of the shortcut for the exe.
people who casually read in the forums, even topics not related to their special interests, should have heard it meanwhile, because, as I said, it was told very often.
Alan asked for "the folder of your file location", not for "the current folder", why your answer obviously was wrong.
sorry Bernd.
the problem is, if people search for this task, they may not see my posting if I did not post it large-bold, and take the wrong solution.
every case of this will lead to another "why does my stuff not load"-thread later on.
oh... and have a nice day.
Re: How to find the folder of your file location
AlanFoo, better ask a dumb question than none at all... Besides, I'm a little experienced and I manage to get lost myself time after time, so I know the feeling 

( 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: How to find the folder of your file location
Hello all,
I am a bit embarrassed to have caused the exchanges ...
Yes, as a novice in purebasic, I do understand the significance of each code stated.
Thanks guys for the explanations. I Am still learning as I convert more of my old QB45 programs to purebasic.
Cheers
Alan
I am a bit embarrassed to have caused the exchanges ...

Yes, as a novice in purebasic, I do understand the significance of each code stated.
Thanks guys for the explanations. I Am still learning as I convert more of my old QB45 programs to purebasic.
Cheers
Alan