shutil.move has a mind of its own

D

Daniel Bickett

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
 
D

Don

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
 
D

Daniel Bickett

Don said:
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 said:
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
 
M

Michael Hoffman

Daniel said:
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?
 
I

Istvan Albert

Daniel said:
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.
 
S

Steve Holden

Daniel said:
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
 
S

Steve Holden

Daniel said:
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
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top