shutil.move has a mind of its own

Discussion in 'Python' started by Daniel Bickett, Jan 11, 2005.

  1. 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
     
    Daniel Bickett, Jan 11, 2005
    #1
    1. Advertising

  2. Daniel Bickett

    Don Guest

    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
     
    Don, Jan 12, 2005
    #2
    1. Advertising

  3. 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
     
    Daniel Bickett, Jan 12, 2005
    #3
  4. 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
     
    Michael Hoffman, Jan 12, 2005
    #4
  5. 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.
     
    Istvan Albert, Jan 12, 2005
    #5
  6. Daniel Bickett

    Steve Holden Guest

    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
     
    Steve Holden, Jan 12, 2005
    #6
  7. Daniel Bickett

    Steve Holden Guest

    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
     
    Steve Holden, Jan 12, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Hurlman
    Replies:
    5
    Views:
    1,947
    Greg Hurlman
    Dec 4, 2003
  2. Chris Jackson
    Replies:
    0
    Views:
    530
    Chris Jackson
    Dec 9, 2003
  3. Saverio M.
    Replies:
    0
    Views:
    537
    Saverio M.
    Jul 3, 2006
  4. Delaney, Timothy C (Timothy)

    RE: shutil.move has a mind of its own

    Delaney, Timothy C (Timothy), Jan 11, 2005, in forum: Python
    Replies:
    3
    Views:
    451
    Neil Benn
    Jan 11, 2005
  5. Fletcher Johnson

    Why is the shutil module called shutil?

    Fletcher Johnson, Sep 24, 2011, in forum: Python
    Replies:
    11
    Views:
    895
    alex23
    Sep 26, 2011
Loading...

Share This Page