When opening a file without drive letter in the path name takes windows the drive from the working directory of the program or what does it do?
Printable View
When opening a file without drive letter in the path name takes windows the drive from the working directory of the program or what does it do?
do you mean file handling ?
When you run a program, you run it in the context of a working directory. So if you open a file without a drive letter (relative path), it will be in relation to the current working directory. It may also search PATH, but I can't say for sure on that and wouldn't count on that.
Epy is very close...
Your working directory ( GetCurrentDirectory() and SetCurrentDirectory() ) is considered to be your "home" directory... Relative paths are deemed to originate from there. It works like this...
E:\myfiles\this\that\private
This is an explicit path, it leads directly to the last folder in the chain (private, in this example)
\myfiles\this\that\private
This is a root path... windows will substitue in the current drive and expand it to an explicit path like this...
D:\myfiles\this\that\private
myfiles\this\that\private
This is a relative path ... windows will concatenate it onto the end of your current directory, like this...
c:\projects\coding\myfiles\this\that\private
In the second two examples, it is very likely the path won't exist and windows will not create it for you automatically...
A Windows process in a sense has multiple current directories, one for each volume. For instance, if you set the current directory to "D:\foo", then set it to "C:\windows", then set it to "D:", you end up in "D:\foo", not the root of D:
There is only one actual "working directory" but the last working directory of each volume is memorized.
You can test this from a command prompt.
Code:C:\> d:
D:\> cd foo
D:\foo> c:
C:\> dir d:
[[[ the contents of d:\foo will be listed]]]
That truthfulness of that depends on how picky you want to be. At the plain Win32 level there's only ever one current directory and nothing is remembered. cmd hacks it for back compat using weird environment variables to save them.
If you use _chdir from the MS CRT to change directories, that will also create these environment variables. They're looked up and returned if you call GetFullPathName("X:" ...), despite that being deeper in the OS where there is no such concept.
Not that anybody in this thread whose username doesn't start with an a cares about this, or that it affects the OP in any wayCode:#include <windows.h>
#include <direct.h>
#include <stdio.h>
int main()
{
WCHAR buffer[MAX_PATH];
SetCurrentDirectoryW(L"C:\\test");
SetCurrentDirectoryW(L"D:\\");
GetFullPathNameW(L"C:", MAX_PATH, buffer, NULL);
// this will print C:\ or whatever the current C:\ directory
// was in cmd if you launch it from there
printf("%S\n", buffer);
_chdir("C:\\Test");
_chdir("D:\\");
GetFullPathNameW(L"C:", MAX_PATH, buffer, NULL);
// will print C:\test
printf("%S\n", buffer);
return 0;
}