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?
Printable View
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?
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.
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.
Guys, I'm a bit confused. According to MSDN and the link that Viggy posted above:, but ovidiucucu says that:Quote:
the current directory; it is the directory in which the active application started, unless explicitly changed.
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.Quote:
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.
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. ;)
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?
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)?
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).
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.