ENH RQST: chdir in boost::filesystem
I have recently moved back to C++ from a 2 year spell with Java. The C++ code I am working on is for Windoze with Visual Studio 8. We are using boost 1.34.1. The prog I am working on has to do a few filesystem things so I have started to use boost::filesystem. However, there does not seem to be a way to change the current working directory using boost::filesystem. So I am forced to use chdir, which is _chdir on Windoze. On Unix the header for the prototype is in unistd.h, on Windoze it is in direct.h. So its back to good old ifdefs. Suddenly, java looks more attractive. Ifdefs are just so nostalgic.... Is there any chance this can be added to boost please? I realise that there may be more to it than just wrapping the chdir/_chdir call. There is the whole issue of return values versus exceptions, errno etc etc. I do not know what the current thinking is about these things in boost. Perhaps someone can enlighten me? -- Regards, Andrew M. http://www.andrewpetermarlow.co.uk
On Tue, Nov 3, 2009 at 1:05 PM, Andrew Marlow
I have recently moved back to C++ from a 2 year spell with Java. The C++ code I am working on is for Windoze with Visual Studio 8. We are using boost 1.34.1. The prog I am working on has to do a few filesystem things so I have started to use boost::filesystem. However, there does not seem to be a way to change the current working directory using boost::filesystem. So I am forced to use chdir, which is _chdir on Windoze. On Unix the header for the prototype is in unistd.h, on Windoze it is in direct.h. So its back to good old ifdefs. Suddenly, java looks more attractive. Ifdefs are just so nostalgic....
Is there any chance this can be added to boost please?
I realise that there may be more to it than just wrapping the chdir/_chdir call. There is the whole issue of return values versus exceptions, errno etc etc. I do not know what the current thinking is about these things in boost. Perhaps someone can enlighten me?
Have you considered upgrading to a more recent version of boost? 1.34.1 is really very old, and (as luck would have it) there is a function boost::filesystem::current_path(const Path&) as of 1.35 that does exactly this.
I'm pretty sure what you're asking is impossible using standard Java -
doing it requires kicking off a new VM or fiddling with the internals
of... System was it? I don't recall, but I saw code online for doing
this and not only was it non-standard, it was UGLY. Involved setting a
reference to null to force it to reevaluate something.
Point being, I'm not sure why this would make Java look attractive. On
the other hand, though, I have yet to run into a situation where I'd
need such a thing to happen - if I have a path relative to a directory
other than the working directory prefixing it is usually enough.
In any case, it's nice to hear Boost can do this for us.
On Tue, Nov 3, 2009 at 2:05 PM, Andrew Marlow
started to use boost::filesystem. However, there does not seem to be a way to change the current working directory using boost::filesystem. So I am <SNIP> old ifdefs. Suddenly, java looks more attractive. Ifdefs are just so
participants (3)
-
Andrew Marlow
-
John B. Turpish
-
Zachary Turner