A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/338045.html below:

simple problem with os.rename() parameters

simple problem with os.rename() parameters - path with spacesPeter Hansen peter at engcorp.com
Sun Sep 11 00:19:37 EDT 2005
Tom wrote:
> Peter Hansen wrote:
>> Where do you think those double quotation marks came from?  What 
>> happens if you try the following instead of using the variables you 
>> were trying to use?
>>
>> os.rename("e:\\music\\Joni Mitchell\\ogg-8",
>>      "e:\\music.ogg\\Joni Mitchell\\ogg-8")
>>
>> Now try it with this and observe how you get (I predict) the same 
>> error message as you originally got, and note what your mistake was:
>>
>> os.rename('"e:\\music\\Joni Mitchell\\ogg-8"',
>>      '"e:\\music.ogg\\Joni Mitchell\\ogg-8"')
> 
> 
> This produced the msg:
> OSError: [Errno 22] Invalid argument

Presumably "this" means the second one, whereas for the first you got a 
different message?  The latter is clearly invalid, since paths can't 
contain quotation marks.  The former would work provided the folder 
"music.ogg/Joni Mitchell" existed.

> The problem seems to be that I'm trying to create more than one 
> directory at a time.  In the above example, the dir 'Joni Mitchell' 
> doesn't exist.

If that were true, and the only problem, you would get a different 
error: OSError: [Errno 2] No such file or directory

> The functions that I'm calling (os.rename and shutil.move) use mkdir, 
> not makedirs.  The solution is for me to use makedirs with all of the 
> path except the leaf before I move/rename the old dir.

Regardless of the issue with error messages, that sounds like it does 
explain your problem.  Great! :-)

-Peter

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4