Newbie Copy Question

S

Stacy

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 :)
 
P

Peter Hansen

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

Stacy

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
 
P

Peter Hansen

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

Michael Geary

Peter said:
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 said:
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
 
P

Peter Hansen

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

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top