470,848 Members | 1,709 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

boost::filesystem::create_directoy()

Daz
Hi everyone. I am not sure of where best to post this message.

I have spent 2 days now trying to answer this question to no avail, and
I am gradually reaching the end of my tether.

I am trying to figure out how to:
see if a directory exists (using the whole path, not a folder in the
current directory).
if not, make the director( y | ies )

I think it may be something to do with
boost::filesystem::directory_iterator, but I can't be 100% sure on how
to use it if this is the case.

Could someone explain how I might go about seeing if "C:\test" exists,
even though the CWD is "C:\documents and settings". I have checked the
documentation which I didn't really understand, and can't seem to find
any other resources that don't require you to be a C++ graduate, to
understand them.

I am sure there is a really simple solution, and that I may have just
got myself lost in the complexities rather than the simplicities.

As there doesn't appear to be any articles on usenet (that I can find)
containing this information, any input/debates would be appreciated as
always.

Best wishes.
Daz

May 10 '06 #1
12 2311
Daz a écrit :
I am trying to figure out how to:
see if a directory exists (using the whole path, not a folder in the
current directory).
if not, make the director( y | ies )


Hi Daz,

Did you try boost::filesystem::create_directories()?
http://www.boost.org/libs/filesystem...te_directories

HTH,

Éric

May 10 '06 #2
Daz

Eric.Malenf...@gmail.com wrote:
Daz a écrit :
I am trying to figure out how to:
see if a directory exists (using the whole path, not a folder in the
current directory).
if not, make the director( y | ies )


Hi Daz,

Did you try boost::filesystem::create_directories()?
http://www.boost.org/libs/filesystem...te_directories


Hi Eric,

Yes, that was among the first places I looked. Unfortunately, I don't
understand what it's saying (although it may be giving me the answer I
require). I am trying to understand the code, but can't quite figure it
out.

Thanks for the reply.

May 10 '06 #3
JCR
As far as I can remeber, the documentation explicitly discourages
absolute paths as bad programming practice. To use absolute Path, I am
doing as below: maybe there is a better way. I would be curious.
bf::path pathOut("c:", bf::no_check);
pathOut /= "/XXX/";
pathOut /= YYY;

May 10 '06 #4
Daz
I think my main problem is that I am unsure what the 'path' in '(const
path & ph)' actually defines. I have tried to trace it back to the
originating header file, but all I get is a listbox telling me to
"resolve ambiguity". This is quite tought considering I only want to
create a directory, lol.

May 10 '06 #5
Daz

JCR wrote:
As far as I can remeber, the documentation explicitly discourages
absolute paths as bad programming practice. To use absolute Path, I am
doing as below: maybe there is a better way. I would be curious.
bf::path pathOut("c:", bf::no_check);
pathOut /= "/XXX/";
pathOut /= YYY;


Excellent! That's exactly what I wanted to do. Just as I suspected,
there's always a simpler solution, than the one I am currently
devising. I have teken into your account that I should not use absolute
paths, although I am not sure why. I will certainly look into doing it
another way. I would be interested to see where the documentation
discourages absolute paths, not because I don't believe you, but
because you have clearly looked somewhere I have not, and the document
you are referring to, may be of some use to me.

Thanks JCR. Your help is much appreciated!

May 10 '06 #6
JCR
http://boost.org/libs/filesystem/doc...htm#Normalized
with the section "Good programming practice: relative paths"

May 10 '06 #7
Well, nothing radically better but:
- Using the "native" checker would bring some... checking
- Why use operator/= instead of passing the full path to the ctor (ie:
bf::path("c:/XXX/YYY", bf::native)) ?

May 10 '06 #8
Daz

JCR wrote:
http://boost.org/libs/filesystem/doc...htm#Normalized
with the section "Good programming practice: relative paths"


Thanks, the link has been bookmarked accordingly. Why would it be a
problem using absolute paths? Is it because of possible portability
issues? What if the bath you build is managed by a function that builds
the string depending on the task it is carrying out? Does that change
anything, or is it still bed practice?

May 10 '06 #9
Daz

Eric.Malenf...@gmail.com wrote:
Well, nothing radically better but:
- Using the "native" checker would bring some... checking
- Why use operator/= instead of passing the full path to the ctor (ie:
bf::path("c:/XXX/YYY", bf::native)) ?


What does the 'native' checker actually check for?

May 10 '06 #10
It (obviously) depends on the target platform. On windows, it calls
windows_name:
http://www.boost.org/libs/filesystem...m#windows_name

May 10 '06 #11
Daz
Great! I now have a much clearer concept on subject, and I have my
program doing exactly what I wanted it to.

Thanks a lot guys! Much appreciated. :)

May 10 '06 #12
Daz wrote:
JCR wrote:

http://boost.org/libs/filesystem/doc...htm#Normalized
with the section "Good programming practice: relative paths"

Thanks, the link has been bookmarked accordingly. Why would it be a
problem using absolute paths? Is it because of possible portability
issues? What if the bath you build is managed by a function that builds
the string depending on the task it is carrying out? Does that change
anything, or is it still bed practice?


c:\temp doesn't exist on probably anything but windows, and I might not
have a c: drive on my windows machine.

Joe
May 11 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.