|
-
September 24th, 2009, 10:49 PM
#1
Confused over GetCurrentDirectory
Does each process have its current directory reset to the folder where it was started from at the beginning, or is it some sort of a global value that is not changed like that?
And the second question, what can change that current directory?
-
September 25th, 2009, 07:43 AM
#2
Re: Confused over GetCurrentDirectory
It's part of the environment inherited by the application from the OS at execution time, so it's a little of both.
As far as I know, there's no way to change it without directly mucking with the environment table for the application and this would likely screw up many of the standard C/C++ library functions.
-
September 25th, 2009, 03:45 PM
#3
Re: Confused over GetCurrentDirectory
-
September 25th, 2009, 04:12 PM
#4
Re: Confused over GetCurrentDirectory
 Originally Posted by ahmd
Does each process have its current directory reset to the folder where it was started from at the beginning [...]
No. The current directory of a process may be or may be not the folder from where it is launched.
See for an example the lpCurrentDirectory parameter of CreateProcess function.
Also it may be changed anytime by a call of SetCurrentDirectory, GetOpenFileName, and so on.
-
September 25th, 2009, 07:07 PM
#5
Re: Confused over GetCurrentDirectory
Guys, I'm a bit confused. According to MSDN and the link that Viggy posted above:
the current directory; it is the directory in which the active application started, unless explicitly changed.
, but ovidiucucu says that:
No. The current directory of a process may be or may be not the folder from where it is launched. See for an example the lpCurrentDirectory parameter of CreateProcess function.
The reason I need to know this is because I'm tryin to convert a relative path to an absolute one (that path will be used in my app only) and GetCurrentDirectory seems to be the only way to do it.
-
September 26th, 2009, 01:10 AM
#6
Re: Confused over GetCurrentDirectory
I said the same thing in other words.
To get the directory in which the executable file is, you can call GetModuleFileName function. See this FAQ: http://www.codeguru.com/forum/showthread.php?t=312471.
// there are also other Codeguru FAQs which can make you less confused.
-
September 26th, 2009, 02:05 AM
#7
Re: Confused over GetCurrentDirectory
Yeah, I thought about it, but you see it's not that easy. Say, if I call CreateFile with "test.txt", where will test.txt be created?
-
September 26th, 2009, 06:09 AM
#8
Re: Confused over GetCurrentDirectory
 Originally Posted by ahmd
Say, if I call CreateFile with "test.txt", where will test.txt be created?
In the current directory of the process.
Last edited by ovidiucucu; September 26th, 2009 at 06:18 AM.
-
September 26th, 2009, 11:43 AM
#9
Re: Confused over GetCurrentDirectory
OK, I apologize for my tenaciousness, but does this mean that I need to use GetCurrentDirectory to convert that relative path to an absolute one (for my program only)?
-
September 26th, 2009, 11:48 AM
#10
Re: Confused over GetCurrentDirectory
But why do you need that? If you know the current directory, or have set current directory, you need not to use absolute path.
But personally, I always prefer using absolute path (without relying on current directory, since drive change may make matter worse).
-
September 26th, 2009, 12:09 PM
#11
Re: Confused over GetCurrentDirectory
I'm sorry, but the question of why I need it is not what is discussed on this thread. But since you asked, I need it to compare two file paths (that can be provided by a user) and that doesn't seem to be an easy task.
-
September 28th, 2009, 02:46 PM
#12
Re: Confused over GetCurrentDirectory
 Originally Posted by ahmd
Guys, I'm a bit confused. According to MSDN and the link that Viggy posted above:, but ovidiucucu says that:
The reason I need to know this is because I'm tryin to convert a relative path to an absolute one (that path will be used in my app only) and GetCurrentDirectory seems to be the only way to do it.
I believe that ovidiucucu was referring to the directory in which the EXE itself resides.
Viggy
-
September 28th, 2009, 02:59 PM
#13
Re: Confused over GetCurrentDirectory
 Originally Posted by ahmd
[...] I need it to compare two file paths (that can be provided by a user) [...]
That's far, far away of both thread title and OP (original post).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|