Newbie Copy Question

Discussion in 'Python' started by Stacy, Jun 9, 2004.

  1. Stacy

    Stacy Guest

    Hi,

    I'm new to Python (about 2 weeks) and I want to use the shutil module
    to copy files from Windows XP folders to my jump drive. My problem is
    that I can't figure out how to make Python deal with the spaces in
    Windows folder and file names. I tried putting the path in quotes
    (like you do at a DOS prompt) but still no good. I searched
    python.org and can't find an answer....any ideas?

    Thanks!

    Stacy :)
    Stacy, Jun 9, 2004
    #1
    1. Advertising

  2. Stacy

    Peter Hansen Guest

    Stacy wrote:

    > I'm new to Python (about 2 weeks) and I want to use the shutil module
    > to copy files from Windows XP folders to my jump drive. My problem is
    > that I can't figure out how to make Python deal with the spaces in
    > Windows folder and file names. I tried putting the path in quotes
    > (like you do at a DOS prompt) but still no good. I searched
    > python.org and can't find an answer....any ideas?


    Please post an example of the paths that aren't working. Spaces
    generally work fine, but perhaps the limitation is with your
    "jump drive" (what's that?) rather than with Python itself.
    Another possibility is that you are using single backslashes
    inside the Python strings, without realizing the effect this
    has when certain characters follow the backslash... this is
    because of the "escape sequences" allowed in strings to let
    a programmer produce special characters such as TAB (\t) or
    LF (\n). If that's the case, switching to forward slashes
    should work, or learn to use raw strings as in r'path\file'.

    -Peter
    Peter Hansen, Jun 9, 2004
    #2
    1. Advertising

  3. Stacy

    Stacy Guest

    Thanks for the response, Peter! Another reader helped me out, too,
    but I figured out what the problem was...the folders and file names
    are case-sensitive! Once I changed documents and settings...blah blah
    blah to Documents and Settings blah blah blah it worked just fine.
    I'm doing some computer migrations at work and I wanted to write a
    frozen binary to copy all the important files automatically to my jump
    drive for transfer to the new PC. BTW a jump drive is just a USB
    thumb drive that I use to copy stuff from the old computers to the new
    :)

    Thanks again,

    Stacy

    Peter Hansen <> wrote in message news:<>...
    > Stacy wrote:
    >
    > > I'm new to Python (about 2 weeks) and I want to use the shutil module
    > > to copy files from Windows XP folders to my jump drive. My problem is
    > > that I can't figure out how to make Python deal with the spaces in
    > > Windows folder and file names. I tried putting the path in quotes
    > > (like you do at a DOS prompt) but still no good. I searched
    > > python.org and can't find an answer....any ideas?

    >
    > Please post an example of the paths that aren't working. Spaces
    > generally work fine, but perhaps the limitation is with your
    > "jump drive" (what's that?) rather than with Python itself.
    > Another possibility is that you are using single backslashes
    > inside the Python strings, without realizing the effect this
    > has when certain characters follow the backslash... this is
    > because of the "escape sequences" allowed in strings to let
    > a programmer produce special characters such as TAB (\t) or
    > LF (\n). If that's the case, switching to forward slashes
    > should work, or learn to use raw strings as in r'path\file'.
    >
    > -Peter
    Stacy, Jun 10, 2004
    #3
  4. Stacy

    Peter Hansen Guest

    Stacy wrote:

    > Thanks for the response, Peter! Another reader helped me out, too,
    > but I figured out what the problem was...the folders and file names
    > are case-sensitive! Once I changed documents and settings...blah blah
    > blah to Documents and Settings blah blah blah it worked just fine.


    My guess is that you've misinterpreted what happened, but I've
    been wrong before.

    Windows is almost never (ever?) case-sensitive, though it does
    tend to preserve the case of filenames (sometimes, when it wants to).
    Unless the jump drive is somehow case-sensitive, I doubt this
    was the problem.

    Note that if you were still using backslashes, and include paths
    that had escape sequences in them, switching to upper case
    would avoid the bad side-effects of the backslashes, leading
    you to think the paths were case-sensitive when they really
    weren't.

    That would mean that any paths that had components following
    a slash that began with \a, \b, \f, \n, \r, \t, \v, \x
    (give or take a couple) would magically appear to work when
    converted to \A, \B, etc.

    But, as I said, I could be wrong.

    -Peter
    Peter Hansen, Jun 10, 2004
    #4
  5. > Stacy wrote:
    > > Thanks for the response, Peter! Another reader helped me
    > > out, too, but I figured out what the problem was...the folders
    > > and file names are case-sensitive! Once I changed documents
    > > and settings...blah blah blah to Documents and Settings blah
    > > blah blah it worked just fine.


    Peter Hansen wrote:
    > My guess is that you've misinterpreted what happened, but I've
    > been wrong before.
    >
    > Windows is almost never (ever?) case-sensitive, though it does
    > tend to preserve the case of filenames (sometimes, when it
    > wants to). Unless the jump drive is somehow case-sensitive,
    > I doubt this was the problem.


    This depends on the filesystem, but all of the filesystems in common use on
    Windows are case-preserving (all of the time, not just when Windows "wants
    to" <g>) and case-insensitive.

    > Note that if you were still using backslashes, and include paths
    > that had escape sequences in them, switching to upper case
    > would avoid the bad side-effects of the backslashes, leading
    > you to think the paths were case-sensitive when they really
    > weren't.
    >
    > That would mean that any paths that had components following
    > a slash that began with \a, \b, \f, \n, \r, \t, \v, \x
    > (give or take a couple) would magically appear to work when
    > converted to \A, \B, etc.


    +1 (insightful!)

    -Mike
    Michael Geary, Jun 10, 2004
    #5
  6. Stacy

    Peter Hansen Guest

    Michael Geary wrote:

    > Peter Hansen wrote:
    >>Windows is almost never (ever?) case-sensitive, though it does
    >>tend to preserve the case of filenames (sometimes, when it
    >>wants to). Unless the jump drive is somehow case-sensitive,
    >>I doubt this was the problem.

    >
    > This depends on the filesystem, but all of the filesystems in common use on
    > Windows are case-preserving (all of the time, not just when Windows "wants
    > to" <g>) and case-insensitive.


    You're right... I was confusing myself because of the
    behaviour of Windows Explorer, where it will magically
    change the appearance of filenames that are ALLCAPS
    depending on the setting of some flag. It's not really
    changing the name, just how it's displayed, and it's
    not a filesystem thing anyway, as you say.

    -Peter
    Peter Hansen, Jun 10, 2004
    #6
    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. John Blair
    Replies:
    4
    Views:
    1,075
    John Saunders
    Jan 12, 2005
  2. Steve Richter
    Replies:
    4
    Views:
    5,435
    Steve Richter
    Apr 18, 2005
  3. Steve Franks

    Copy Web tool does not copy sub dirs?

    Steve Franks, Sep 14, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    373
    Steve Franks
    Sep 15, 2005
  4. Alex
    Replies:
    2
    Views:
    1,199
  5. Replies:
    26
    Views:
    2,083
    Roland Pibinger
    Sep 1, 2006
Loading...

Share This Page