boost::filesystem::create_directoy()

D

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
 
J

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;
 
D

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.
 
D

Daz

JCR said:
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!
 
E

Eric.Malenfant

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)) ?
 
D

Daz

JCR said:
http://boost.org/libs/filesystem/doc/path.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?
 
D

Daz

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?
 
D

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. :)
 
J

Joe Van Dyk

Daz said:
JCR wrote:




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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top