Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > spaces at ends of filenames or directory names on Win32

Reply
Thread Tools

spaces at ends of filenames or directory names on Win32

 
 
rtilley
Guest
Posts: n/a
 
      02-23-2006
# Spaces are present before and after the XXX
filename = ' XXX '

new_filename = filename.strip()

if new_filename != filename:
print filename

Macs allow these spaces in file and folder names. Which is OK. The
problem arises when the file or folder is copied to a PC running Windows
from a Mac. Windows allows the Mac to copy the file to it, but when
Windows itself attempts to do anything with the file it strips the
spaces and then tries to move it, copy it, etc and complains that the
file isn't there!

I can rectify this by striping the spaces from the files and folders on
the Mac before they are copied to the PC or mounting the Windows share
from the Mac and running a recursive strip program I wrote, but Windows
will not allow the whitespace removal directly from within Windows....
how annoying!

For example... tell windows to move a file named ' XXX ' (one space
before and one space after the filename). Windows will complain that
file 'XXX' does not exist. It's correct of course, 'XXX' does not exist,
but ' XXX ' does indeed exist.

Can anyone rescue me from this madness

Many Thanks,
Brad
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      02-23-2006
rtilley wrote:
> # Spaces are present before and after the XXX
> filename = ' XXX '
>
> new_filename = filename.strip()
>
> if new_filename != filename:
> print filename
>
> Macs allow these spaces in file and folder names. Which is OK. The
> problem arises when the file or folder is copied to a PC running Windows
> from a Mac. Windows allows the Mac to copy the file to it, but when
> Windows itself attempts to do anything with the file it strips the
> spaces and then tries to move it, copy it, etc and complains that the
> file isn't there!
>
> I can rectify this by striping the spaces from the files and folders on
> the Mac before they are copied to the PC or mounting the Windows share
> from the Mac and running a recursive strip program I wrote, but Windows
> will not allow the whitespace removal directly from within Windows....
> how annoying!
>
> For example... tell windows to move a file named ' XXX ' (one space
> before and one space after the filename). Windows will complain that
> file 'XXX' does not exist. It's correct of course, 'XXX' does not exist,
> but ' XXX ' does indeed exist.
>
> Can anyone rescue me from this madness
>
> Many Thanks,
> Brad


How about not naming files with leading and trailing spaces on
the Mac? Seems like a bad habit that needs breaking .

-Larry Bates
 
Reply With Quote
 
 
 
 
rtilley
Guest
Posts: n/a
 
      02-23-2006
Larry Bates wrote:
> How about not naming files with leading and trailing spaces on
> the Mac? Seems like a bad habit that needs breaking .
>
> -Larry Bates


Users will be users! Tell that to the guys and gals on Macs who like to
make a folder sort based on the number of spaces they've placed in the
front of the filenames
 
Reply With Quote
 
Larry Bates
Guest
Posts: n/a
 
      02-23-2006
rtilley wrote:
> Larry Bates wrote:
>> How about not naming files with leading and trailing spaces on
>> the Mac? Seems like a bad habit that needs breaking .
>>
>> -Larry Bates

>
> Users will be users! Tell that to the guys and gals on Macs who like to
> make a folder sort based on the number of spaces they've placed in the
> front of the filenames


Sounds like you should change leading/trailing spaces to something
like underlines instead of stripping them off the filename. That way
you preserve the character positions, visually the filenames are very
close. Problem is that underlines sort to bottom instead of to the
top of a list of files.

On second thought, if you replace spaces with dashes they will sort
correctly, but they will look odd.

Pick your poison.

-Larry
 
Reply With Quote
 
mensanator@aol.com
Guest
Posts: n/a
 
      02-23-2006
rtilley wrote:
> # Spaces are present before and after the XXX
> filename = ' XXX '
>
> new_filename = filename.strip()
>
> if new_filename != filename:
> print filename
>
> Macs allow these spaces in file and folder names. Which is OK. The
> problem arises when the file or folder is copied to a PC running Windows
> from a Mac. Windows allows the Mac to copy the file to it, but when
> Windows itself attempts to do anything with the file it strips the
> spaces and then tries to move it, copy it, etc and complains that the
> file isn't there!
>
> I can rectify this by striping the spaces from the files and folders on
> the Mac before they are copied to the PC or mounting the Windows share
> from the Mac and running a recursive strip program I wrote, but Windows
> will not allow the whitespace removal directly from within Windows....
> how annoying!
>
> For example... tell windows to move a file named ' XXX ' (one space
> before and one space after the filename). Windows will complain that
> file 'XXX' does not exist. It's correct of course, 'XXX' does not exist,
> but ' XXX ' does indeed exist.
>
> Can anyone rescue me from this madness


Use quatation marks.

>copy tt1.txt " XXX "

1 file(s) copied.

>dir XXX

Volume in drive C is XXXXPXXABA
Volume Serial Number is 90C0-740E

Directory of C:\Documents and Settings\Desktop

File Not Found

>dir " XXX

Volume in drive C is XXXXPXXABA
Volume Serial Number is 90C0-740E

Directory of C:\Documents and Settings\Desktop

02/06/2006 07:05p 10 XXX
1 File(s) 10 bytes
0 Dir(s) 2,063,822,848 bytes free

>dir *.

Volume in drive C is XXXXPXXABA
Volume Serial Number is 90C0-740E

Directory of C:\Documents and Settings\Desktop

02/23/2006 03:20p <DIR> .
02/23/2006 03:20p <DIR> ..
02/06/2006 07:05p 10 XXX
01/20/2006 04:53p <DIR> AGMP
01/20/2006 04:53p <DIR> BPWR Fe-Mn
01/20/2006 04:53p <DIR> GM
01/20/2006 04:53p <DIR> IDEM response
01/20/2006 04:53p <DIR> msgs
01/20/2006 04:53p <DIR> New Folder
02/08/2006 05:29p <DIR> New Folder (2)
01/20/2006 04:53p <DIR> OCAML
01/20/2006 04:53p <DIR> review05
01/20/2006 04:53p <DIR> scanned docs
02/17/2006 03:07p <DIR> USS repository
1 File(s) 10 bytes
13 Dir(s) 2,063,822,848 bytes free

Note that the trailing quote isn't always necessary.
Note from the last listing that the XXX file is indented one space.

>
> Many Thanks,
> Brad


 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-23-2006
On Thu, 23 Feb 2006 14:30:22 -0600, Larry Bates wrote:

> How about not naming files with leading and trailing spaces on
> the Mac? Seems like a bad habit that needs breaking .


Why is it a bad habit? Because *Windows* is primitive enough that it can't
cope with leading and trailing spaces? I don't see why Windows' lack is
Mac users' problem.


--
Steven.

 
Reply With Quote
 
Larry Bates
Guest
Posts: n/a
 
      02-23-2006

Steven D'Aprano wrote:
> On Thu, 23 Feb 2006 14:30:22 -0600, Larry Bates wrote:
>
>> How about not naming files with leading and trailing spaces on
>> the Mac? Seems like a bad habit that needs breaking .

>
> Why is it a bad habit? Because *Windows* is primitive enough that it can't
> cope with leading and trailing spaces? I don't see why Windows' lack is
> Mac users' problem.
>
>

It is a problem because the poster says it is a problem for him.
If they want to leave the files on a Mac, there is no problem.

IMHO leading and/or trailing spaces in filenames is asking for
incompatibilities with cross-platform file access. Much like
using single-quote in filenames which are perfectly legal in
DOS/Windows, but Linux doesn't like much.

-Larry Bates
 
Reply With Quote
 
Jeffrey Schwab
Guest
Posts: n/a
 
      02-24-2006
Larry Bates wrote:

> IMHO leading and/or trailing spaces in filenames is asking for
> incompatibilities with cross-platform file access.


With what platforms specifically?

> Much like
> using single-quote in filenames which are perfectly legal in
> DOS/Windows, but Linux doesn't like much.


Uh... What Linux are you using? And what FS?

$ touch "'" && ls
'
$ rm "'"
$
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-24-2006
On Thu, 23 Feb 2006 17:49:31 -0600, Larry Bates wrote:

> Steven D'Aprano wrote:
>> On Thu, 23 Feb 2006 14:30:22 -0600, Larry Bates wrote:
>>
>>> How about not naming files with leading and trailing spaces on
>>> the Mac? Seems like a bad habit that needs breaking .

>>
>> Why is it a bad habit? Because *Windows* is primitive enough that it can't
>> cope with leading and trailing spaces? I don't see why Windows' lack is
>> Mac users' problem.
>>
>>

> It is a problem because the poster says it is a problem for him.


Absolutely.

Now read my statement again. Why is it a problem for the Mac _users_?

I use Linux, Windows and Mac, in varying amounts. I'm fully aware of the
problems of transferring files from one platform to another. When it
affects _me_, I may choose to dumb down to the lowest common denominator
so as to save _me_ problems. But wearing my user hat, if a developer came
to me telling me I had to avoid using features on my platform of choice in
order to make his life easier, I'd say to him "So why exactly are we
paying you the big bucks? That's your problem, you solve it."



--
Steven.

 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a
 
      02-25-2006
rtilley <(E-Mail Removed)> wrote:
>
>For example... tell windows to move a file named ' XXX ' (one space
>before and one space after the filename). Windows will complain that
>file 'XXX' does not exist. It's correct of course, 'XXX' does not exist,
>but ' XXX ' does indeed exist.


Are you sure you're doing it right? It works for me. Notice that I have
"x.c" and " x.c " in the same directory at the same time.

C:\tmp\x>copy ..\x.c .
1 file(s) copied.

C:\tmp\x>dir
Volume in drive C has no label.
Volume Serial Number is 70CF-E8F4

Directory of C:\tmp\x

02/24/2006 11:48 PM <DIR> .
02/24/2006 11:48 PM <DIR> ..
02/22/2006 10:49 PM 539 x.c
1 File(s) 539 bytes
2 Dir(s) 50,937,999,360 bytes free

C:\tmp\x>copy x.c " x.c "
1 file(s) copied.

C:\tmp\x>dir
Volume in drive C has no label.
Volume Serial Number is 70CF-E8F4

Directory of C:\tmp\x

02/24/2006 11:48 PM <DIR> .
02/24/2006 11:48 PM <DIR> ..
02/22/2006 10:49 PM 539 x.c
02/22/2006 10:49 PM 539 x.c
2 File(s) 1,078 bytes
2 Dir(s) 50,937,999,360 bytes free

C:\tmp\x>erase " x.c "

C:\tmp\x>dir
Volume in drive C has no label.
Volume Serial Number is 70CF-E8F4

Directory of C:\tmp\x

02/24/2006 11:49 PM <DIR> .
02/24/2006 11:49 PM <DIR> ..
02/22/2006 10:49 PM 539 x.c
1 File(s) 539 bytes
2 Dir(s) 50,937,999,360 bytes free

C:\tmp\x>
--
- Tim Roberts, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
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
Chopping off spaces at both ends Madhusudan Singh Python 3 08-09-2005 04:21 AM
problem with filenames, Filenames and FILENAMES B.J. HTML 4 04-23-2005 08:13 PM
Perl opendir with spaces in directory names JJ Perl Misc 3 11-25-2004 08:06 AM
how to use Perl to rename the filenames and directory names under current and subdirectories recursively? lucy Perl Misc 6 09-03-2004 06:27 AM
Problem with mkmf and spaces in directory names? Daniel Berger Ruby 5 06-26-2004 05:35 AM



Advertisments