File bug?


I am using an environment variable to get a path, so I am doing something similar to this (not with SystemDrive in mine, but good windows example):

In debug mode, it throws that annoying assertion about path not containing a colon, although the environment variable already contains it. And in both debug and release, it ends up making the full path “F:\Programming_Projects\Juce\AProjectName\Debug%SystemDrive%/somedir/someExe.exe”, which ends up being evaluated to “F:\Programming_Projects\Juce\AProjectName\Debug\C:/somedir/someExe.exe”. Not what I wanted…



Well it won’t automatically replace environment variables in pathnames for you - and in fact that’d be a bit tricky to do, as the % character is a legal filename char, so the string you’ve given it there could be a perfectly legitimate filename.


But how can I prevent it pre-pending the cwd without editing your source?


How about using Win32 API like SHGetFolderPath with CSIDL_WINDOWS ?
As you application is Win32 specific, you’ll simply have to create an absolute path in a string this way…


There’s no way to do that with the file class - it always tries to parse the filename. I can’t think of a clean way of working around it either - it’s perfectly legal to create a file called “%SystemDrive%”, so for the file class to always assume that things between % signs should be replaced wouldn’t be correct. You need some kind of pre-parser to replace those bits before making it into a file object.

There are already a bunch of similar juce functions, in SystemStats