Improvement ?

  • Thread starter Jean-Marc Ranger
  • Start date
J

Jean-Marc Ranger

Just wondering:

With Python 2.3.3 for Windows, I understand why
os.makedirs("C:\SomeDirectoryThatDontExist\.\AnotherDirectory") fails
throwing an exception saying "OSError: [Errno 17] File exists" - the
period is like a request to create the same directory a second time.

But is this the expected behavior ? I personaly would prefer to see
this operation succeed - and don't like the idea of writing a
workaround :)

Comments ?

Thanks,

Jean-Marc Ranger
 
M

Michael Geary

Jean-Marc Ranger said:
With Python 2.3.3 for Windows, I understand why
os.makedirs("C:\SomeDirectoryThatDontExist\.\AnotherDirectory")
fails throwing an exception saying "OSError: [Errno 17] File exists" -
the period is like a request to create the same directory a second time.

But is this the expected behavior ? I personaly would prefer to see
this operation succeed - and don't like the idea of writing a
workaround :)

It feels like a bug to me. I would expect os.makedirs to run its argument
through os.path.abspath first. But, you can easily do that yourself:

Also, you got very lucky with your backslashes:

-Mike
 
P

Peter Hansen

Jean-Marc Ranger said:
With Python 2.3.3 for Windows, I understand why
os.makedirs("C:\SomeDirectoryThatDontExist\.\AnotherDirectory") fails
throwing an exception saying "OSError: [Errno 17] File exists" - the
period is like a request to create the same directory a second time.

But is this the expected behavior ? I personaly would prefer to see
this operation succeed - and don't like the idea of writing a
workaround :)

Wouldn't using os.path.normpath() on the string first be a
really really easy workaround?

-Peter
 
H

Heiko Wundram

Am Mittwoch, 5. Mai 2004 21:12 schrieb Jean-Marc Ranger:
But is this the expected behavior ? I personaly would prefer to see
this operation succeed - and don't like the idea of writing a
workaround :)

What you could do is pass the final directory name to os.path.abspath before
you create it. abspath will filter out the unneccesary reference to "."
before returning the name.

HTH!

Heiko.
 
J

Jean-Marc Ranger

Also, you got very lucky with your backslashes:
'C:\\someDirectory\\.\x07notherDirectory'

Oopps....

I need to be more careful. Those names are obviously dummies, but I
could have got stuck by that one easily.

Thanks for spotting it.

And thanks everyone for the hints.

Jean-Marc
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top