By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

shutil.move has a mind of its own

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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
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


Jul 18 '05 #2

P: n/a
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
Jul 18 '05 #3

P: n/a
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
Jul 18 '05 #4

P: n/a
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.
Jul 18 '05 #5

P: n/a
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
Jul 18 '05 #6

P: n/a
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

Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.