Page 1 of 1

How to find the folder of your file location

Posted: Wed Mar 17, 2010 9:23 am
by AlanFoo
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

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 9:34 am
by infratec
Hi Alan,

did you tried GetCurrentDirectory() ?

Bernd

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 10:00 am
by AlanFoo
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

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 10:29 am
by Kaeru Gaman
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.

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 12:22 pm
by Seymour Clufley
Yes, I'd say ProgramFilename() and then GetPathPart().

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 1:51 pm
by infratec
@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:
Gibt den aktuellen Verzeichnis-Namen zurück.
English:
Returns the current directory name.
Nothing more.

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())
to be on the safe side.

Best regards,

Bernd

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 1:58 pm
by UserOfPure
infratec wrote:Why should I search in the forum, when I found a solution in the helpfile, which is/was working for me :?: :?: :?:
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.

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 2:03 pm
by Kaeru Gaman
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.

Re: How to find the folder of your file location

Posted: Wed Mar 17, 2010 7:03 pm
by blueznl
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 :-)

Re: How to find the folder of your file location

Posted: Thu Mar 18, 2010 1:56 am
by AlanFoo
Hello all,

I am a bit embarrassed to have caused the exchanges ... :D

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