Re: Opening a file - File Open Dialog spoils future code
- Posted by Andy Drummond <andy at kest?el?ele.com> Jan 16, 2008
- 552 views
CChris wrote: > > Matt Lewis wrote: > > > > CChris wrote: > > > > > > open() doesn't understand Windows folders, because Windows doesn't have a > > > notion > > > of a current directory. open() uses the PATH environment variable, which > > > is > > > a DOS/Unix thing Windows supports for backward compatibility only) and > > > looks > > > for MyFileName.CFG in places completely different from where Windows looks > > > for > > > them, so it probably just can't see the file there. > > > > I thought that it did, and that %PATH is only used for executables and for > > dlls. What do current_dir() and chdir() do then? > > > > Matt > > All right, I should have checked first, but the bottom line is the same: never > use current_dir() under Windows. Here is what I found on MSDN: > <quote> > The directory at the end of the active path is called the current directory; > it is the directory in which the active application started, unless explicitly > changed. An application can determine which directory is current by calling > the GetCurrentDirectory function. > > An application can change the current directory by calling the > SetCurrentDirectory > function. > </quote> > > I have recently wondered why I wasn't finding ex.err after a program crash. > Searching ex.err on my machine reported 9 different directories, some of which > I'd havd never thought about. Since ex.err is created using > open("ex.err","w"), > I consider the "current directory" to be undefined for practical use: it is > defined, but as something volatile (what is the active application on a > multiprocess > platform?). I'd go as far as recommending to drop support of current_dir() and > chdir() under Windows. > > CChris I disagree CChris. There IS such a thing as the current directory; just because a program can change it doesn't make it less valid. Ex.err gets dumped into the current directory, which is why it is a good idea to use crash_file() to be sure your ex.err gets put where you want. The current directory is where the file system performs actions unless otherwise instructed. If I say something like open("fred.fil","r") Windows will attempt to open that file in the current directory - where ever that may be. Current directory is simply a default folder to access in the absence of further information. I get and set current directory all the time; if you took them out I'd put them into my own library!! AndyD