Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie Copy Question

Reply
Thread Tools

Newbie Copy Question

 
 
Stacy
Guest
Posts: n/a
 
      06-09-2004
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
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      06-09-2004
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
 
Reply With Quote
 
 
 
 
Stacy
Guest
Posts: n/a
 
      06-10-2004
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 <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      06-10-2004
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
 
Reply With Quote
 
Michael Geary
Guest
Posts: n/a
 
      06-10-2004
> 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


 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      06-10-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
algorithm copy from vector to set - newbie question Soumen C++ 5 07-07-2008 05:17 PM
what is Deep Copy, shallow copy and bitwises copy.? saxenavaibhav17@gmail.com C++ 26 09-01-2006 09:37 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
Newbie Question; How can I make a copy righted CD for backup? Scratch Computer Support 10 08-29-2004 09:42 AM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM



Advertisments