Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

shutil.move has a mind of its own

 
 
Daniel Bickett
Guest
Posts: n/a
 
      01-11-2005
Hello,

I'm writing an application in my pastime that moves files around to
achieve various ends -- the specifics aren't particularly important.
The shutil module was chosen as the means simply because that is what
google and chm searches returned most often.

My problem has to do with shutil.move actually putting the files where
I ask it to. Citing code wouldn't serve any purpose, because I am
using the function in the most straight forward manner, ex:

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

In my script, rather than a file being moved to the desired location,
it is, rather, moved to the current working directory (in this case,
my desktop -- without any exceptions, mind you). As it happens, the
desired locations are system folders (running windows xp, the folders
are as follows: C:\WINDOWS, C:\WINDOWS\SYSTEM, C:\WINDOWS\SYSTEM32).
To see if this factor was causing the problem, I tried it using the
interpreter, and found it to be flawless.

My question boils down to this: What factors could possibly cause
shutil.move to fail to move a file to the desired location, choosing
instead to place it in the cwd (without raising any exceptions)?

Thank you for your time,

Daniel Bickett

P.S. I know I said I didn't need to post code, but I will anyway. You
never know

http://rafb.net/paste/results/FcwlEw86.html
 
Reply With Quote
 
 
 
 
Don
Guest
Posts: n/a
 
      01-12-2005
I don't know if this is the problem or, not, but:

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

Needs to have some special handling for the backslashes.

Either:

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

or:

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

-Don


Daniel Bickett wrote:

> Hello,
>
> I'm writing an application in my pastime that moves files around to
> achieve various ends -- the specifics aren't particularly important.
> The shutil module was chosen as the means simply because that is what
> google and chm searches returned most often.
>
> My problem has to do with shutil.move actually putting the files where
> I ask it to. Citing code wouldn't serve any purpose, because I am
> using the function in the most straight forward manner, ex:
>
> shutil.move( "C:\omg.txt" , "C:\folder\subdir" )
>
> In my script, rather than a file being moved to the desired location,
> it is, rather, moved to the current working directory (in this case,
> my desktop -- without any exceptions, mind you). As it happens, the
> desired locations are system folders (running windows xp, the folders
> are as follows: C:\WINDOWS, C:\WINDOWS\SYSTEM, C:\WINDOWS\SYSTEM32).
> To see if this factor was causing the problem, I tried it using the
> interpreter, and found it to be flawless.
>
> My question boils down to this: What factors could possibly cause
> shutil.move to fail to move a file to the desired location, choosing
> instead to place it in the cwd (without raising any exceptions)?
>
> Thank you for your time,
>
> Daniel Bickett
>
> P.S. I know I said I didn't need to post code, but I will anyway. You
> never know
>
> http://rafb.net/paste/results/FcwlEw86.html


 
Reply With Quote
 
 
 
 
Daniel Bickett
Guest
Posts: n/a
 
      01-12-2005
Don wrote:
> I don't know if this is the problem or, not, but:
> [snip]


As I said, that was simply an error when typing the example, and it is
not present in my code. See below.

Neil Benn wrote:
> >Oh, I'm sorry, that was my mistake. The example contained that error,
> >but my code does not.
> >
> > [snip]
> >

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


Which is why I found this so strange, and also why I provided my code.
The paths are user-inputed, and only referenced as variables, so this
is clearly not a matter of escape sequences.

Daniel Bickett
 
Reply With Quote
 
Michael Hoffman
Guest
Posts: n/a
 
      01-12-2005
Daniel Bickett wrote:

> As it happens, the
> desired locations are system folders (running windows xp, the folders
> are as follows: C:\WINDOWS, C:\WINDOWS\SYSTEM, C:\WINDOWS\SYSTEM32).
> To see if this factor was causing the problem, I tried it using the
> interpreter, and found it to be flawless.


I'm not entirely sure what that last sentence means. But does it mean
that shutil.move() works fine if you do it interactively but not in your
code? The simplest interpretation then would be that there is something
wrong in your code.

Why don't you post the debug output of that quoted section of code?

What version of Python are you using? Is it the standard Windows
distribution?
--
Michael Hoffman
 
Reply With Quote
 
Istvan Albert
Guest
Posts: n/a
 
      01-12-2005
Daniel Bickett wrote:

> In my script, rather than a file being moved to the desired location,
> it is, rather, moved to the current working directory (in this case,
> my desktop -- without any exceptions, mind you). As it happens, the


what is the output generated by the lines:

fdir, fname = randFileInfo.new()
debugMess( "Generated file information: %s, %s" % ( fdir, fname ) )

Istvan.
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      01-12-2005
Daniel Bickett wrote:

> Hello,
>
> I'm writing an application in my pastime that moves files around to
> achieve various ends -- the specifics aren't particularly important.
> The shutil module was chosen as the means simply because that is what
> google and chm searches returned most often.
>
> My problem has to do with shutil.move actually putting the files where
> I ask it to. Citing code wouldn't serve any purpose, because I am
> using the function in the most straight forward manner, ex:
>
> shutil.move( "C:\omg.txt" , "C:\folder\subdir" )
>
> In my script, rather than a file being moved to the desired location,
> it is, rather, moved to the current working directory (in this case,
> my desktop -- without any exceptions, mind you). As it happens, the
> desired locations are system folders (running windows xp, the folders
> are as follows: C:\WINDOWS, C:\WINDOWS\SYSTEM, C:\WINDOWS\SYSTEM32).
> To see if this factor was causing the problem, I tried it using the
> interpreter, and found it to be flawless.
>
> My question boils down to this: What factors could possibly cause
> shutil.move to fail to move a file to the desired location, choosing
> instead to place it in the cwd (without raising any exceptions)?
>
> Thank you for your time,
>
> Daniel Bickett
>
> P.S. I know I said I didn't need to post code, but I will anyway. You
> never know
>
> http://rafb.net/paste/results/FcwlEw86.html


AS several people have already suggested, you must have an error in the
calling code, which wasn't included in the pasted snippet.

Also, "data" appears to be a global variable, which leaves us lacking
some useful information.

Does the debugMess() call show the full destination path for the file?

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      01-12-2005
Daniel Bickett wrote:

> Hello,
>
> I'm writing an application in my pastime that moves files around to
> achieve various ends -- the specifics aren't particularly important.
> The shutil module was chosen as the means simply because that is what
> google and chm searches returned most often.
>
> My problem has to do with shutil.move actually putting the files where
> I ask it to. Citing code wouldn't serve any purpose, because I am
> using the function in the most straight forward manner, ex:
>
> shutil.move( "C:\omg.txt" , "C:\folder\subdir" )
>
> In my script, rather than a file being moved to the desired location,
> it is, rather, moved to the current working directory (in this case,
> my desktop -- without any exceptions, mind you). As it happens, the
> desired locations are system folders (running windows xp, the folders
> are as follows: C:\WINDOWS, C:\WINDOWS\SYSTEM, C:\WINDOWS\SYSTEM32).
> To see if this factor was causing the problem, I tried it using the
> interpreter, and found it to be flawless.
>
> My question boils down to this: What factors could possibly cause
> shutil.move to fail to move a file to the desired location, choosing
> instead to place it in the cwd (without raising any exceptions)?
>
> Thank you for your time,
>
> Daniel Bickett
>
> P.S. I know I said I didn't need to post code, but I will anyway. You
> never know
>
> http://rafb.net/paste/results/FcwlEw86.html


AS several people have already suggested, you must have an error in the
calling code, which wasn't included in the pasted snippet.

Also, "data" appears to be a global variable, which leaves us lacking
some useful information.

Does the debugMess() call show the full destination path for the file?

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119

 
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
RE: shutil.move has a mind of its own Delaney, Timothy C (Timothy) Python 3 01-11-2005 04:37 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