Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: shutil.move has a mind of its own

Reply
Thread Tools

RE: shutil.move has a mind of its own

 
 
Delaney, Timothy C (Timothy)
Guest
Posts: n/a
 
      01-11-2005
Daniel Bickett wrote:

> shutil.move( "C:\omg.txt" , "C:\folder\subdir" )

^ ^^ ^
The problem is that backslash is the escape character. In particular,
'\f' is a form feed.

>>> '\o'

'\\o'
>>> '\f'

'\x0c'
>>> '\s'

'\\s'

Notice how for '\o' and '\s' it doubles-up the backslash - this is
because '\o' and '\s' are not valid escapes, and so it treats the
backslash as just a backslash. But '\f' is a valid escape.

You have a couple of options:

1. Use double-backslashes (to escape the backslash):
shutil.move("C:\\omg.txt", "C:\\folder\\subdir")

2. Use forward slashes (they work on Windows for the most part):
shutil.move("C:/omg.txt", "C:/folder/subdir")

3. Build your paths using os.path.join (untested):
shutil.move(os.path.join("C:", "omg.txt"), os.path.join("C:",
"folder", "subdir"))

Tim Delaney
 
Reply With Quote
 
 
 
 
drs
Guest
Posts: n/a
 
      01-11-2005
"Delaney, Timothy C (Timothy)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Daniel Bickett wrote:

> > shutil.move( "C:\omg.txt" , "C:\folder\subdir" )

^ ^^ ^
> The problem is that backslash is the escape character. In particular,
> '\f' is a form feed.


> You have a couple of options:


You can also include an r to make it a raw string if extra or reversed
slashes look odd

shutil.move( r"C:\omg.txt" , r"C:\folder\subdir" )


 
Reply With Quote
 
 
 
 
Daniel Bickett
Guest
Posts: n/a
 
      01-11-2005
Oh, I'm sorry, that was my mistake. The example contained that error,
but my code does not.

Daniel Bickett
 
Reply With Quote
 
Neil Benn
Guest
Posts: n/a
 
      01-11-2005
Daniel Bickett wrote:

>Oh, I'm sorry, that was my mistake. The example contained that error,
>but my code does not.
>
>Daniel Bickett
>
>

To be fair though - I would have expected the method to throw an error
rather than default to cwd.

Neil

--

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : http://www.velocityreviews.com/forums/(E-Mail Removed)
Cenix Website : http://www.cenix-bioscience.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Internet explorer home page has mind of its own. The Real Truth MVP Computer Support 2 10-28-2008 02:01 AM
Re: Internet explorer home page has mind of its own. Mr. Mistery Computer Support 0 10-27-2008 10:07 PM
shutil.move has a mind of its own Daniel Bickett Python 6 01-12-2005 10:46 PM
Re: Checkbox.CheckedChanged still has a mind of its own Chris Jackson ASP .Net 0 12-09-2003 04:57 PM
Checkbox.CheckedChanged has a mind of its own Greg Hurlman ASP .Net 5 12-04-2003 07:14 PM



Advertisments