I get an error with this instruction:
dp = opendir ("%APPDATA%/.");
output:
Couldn't open directory: No such file or directory.
but I don't get an error with this instruction:
dp = opendir ("C:/Users/xrobot/AppData/.");
output:
.
..
Local
LocalLow
Roaming
Why?
opendir
doesn't expand meta variables like %APPDATA%
, the shell does. So such things work from the command line, but not from a program. In your program, you have to use an absolute or relative path.
You can probably obtain the required path with getenv()
,
const char *appData = getenv("APPDATA");
if (appData) {
dp = opendir(appData);
} else {
/* die or recover */
}