/** * vBulletin 3.8.8 Beta 2 CSS * Style: 'Velocity Reviews 3.8'; Style ID: 4 */ @import url("http://www.velocityreviews.com/forums/clientscript/vbulletin_css/style-ae02f2a0-00004.css"); Error copying a file
Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Error copying a file

Reply
Thread Tools

Error copying a file

 
 
Stephen Boulet
Guest
Posts: n/a
 
      04-14-2004
I know that the name of this file is somewhat pathological, but this if
weird:

>>> print myfile

E:\Fritz Reiner\Rimsky-Korsakov--Scheherazade.Debussy--La Mer\01
Symphonic Suite after "A Thousand and One Nights" - The Sea and Sinbad's
Ship.ogg

>>> os.path.isfile(myfile)

True
>>> os.path.getsize(myfile)

12321468L
>>> shutil.copy2(myfile,r'D:\foo.ogg')

Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Python23\Lib\shutil.py", line 82, in copy2
copyfile(src, dst)
File "C:\Python23\Lib\shutil.py", line 37, in copyfile
fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: 'E:\\Fritz
Reiner\\Rimsky-Korsakov--Scheherazade.Debussy--La Mer\\01 Symphonic
Suite after "A Thousand and One Nights" - The Sea and Sinbad\'s Ship.ogg'
>>> shutil.copy(myfile,r'D:\foo.ogg')

Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Python23\Lib\shutil.py", line 71, in copy
copyfile(src, dst)
File "C:\Python23\Lib\shutil.py", line 37, in copyfile
fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: 'E:\\Fritz
Reiner\\Rimsky-Korsakov--Scheherazade.Debussy--La Mer\\01 Symphonic
Suite after "A Thousand and One Nights" - The Sea and Sinbad\'s Ship.ogg'

Must have CD, btw, for you Fritz Reiner fans ... and yes I do own the cd

Stephen
 
Reply With Quote
 
 
 
 
Krzysztof Stachlewski
Guest
Posts: n/a
 
      04-15-2004
Stephen Boulet wrote:
> I know that the name of this file is somewhat pathological, but this if
> weird:
>
> >>> print myfile

> E:\Fritz Reiner\Rimsky-Korsakov--Scheherazade.Debussy--La Mer\01
> Symphonic Suite after "A Thousand and One Nights" - The Sea and Sinbad's
> Ship.ogg


It seems you are on Windows box.
What filesystem do you use?
I have just tried to create such a file, but the filesystem (NTFS)
refuses to use " as part of the name.

--
Stach Tlen: stachobywatelpl, GG: 1811474
Jabber: stach at jabber atman pl
 
Reply With Quote
 
 
 
 
Stephen Boulet
Guest
Posts: n/a
 
      04-16-2004
Krzysztof Stachlewski wrote:
> Stephen Boulet wrote:
>
>> I know that the name of this file is somewhat pathological, but this
>> if weird:
>>
>> >>> print myfile

>> E:\Fritz Reiner\Rimsky-Korsakov--Scheherazade.Debussy--La Mer\01
>> Symphonic Suite after "A Thousand and One Nights" - The Sea and
>> Sinbad's Ship.ogg

>
>
> It seems you are on Windows box.
> What filesystem do you use?
> I have just tried to create such a file, but the filesystem (NTFS)
> refuses to use " as part of the name.


I'm on win2000. The file is on a CD I burned, and I wanted to copy it to
a file name that doesn't have any quotation marks in it. The problem
is that I can't reference the file to begin with. The command:

shutil.copy2(myfile,r'D:\foo.ogg')

can't use the string held in myfile, although os.listdir('directory on
CD') contains it as the first entry.

It would be nice if I could referene the file in a way that would not
cause the copy command to fail.

Stephen
 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      04-16-2004
Stephen Boulet wrote:

> Krzysztof Stachlewski wrote:
>> Stephen Boulet wrote:
>>> >>> print myfile
>>> E:\Fritz Reiner\Rimsky-Korsakov--Scheherazade.Debussy--La Mer\01
>>> Symphonic Suite after "A Thousand and One Nights" - The Sea and
>>> Sinbad's Ship.ogg

>>
>> It seems you are on Windows box.
>> What filesystem do you use?
>> I have just tried to create such a file, but the filesystem (NTFS)
>> refuses to use " as part of the name.

>
> I'm on win2000. The file is on a CD I burned, and I wanted to copy it to
> a file name that doesn't have any quotation marks in it. The problem is
> that I can't reference the file to begin with. The command:
>
> shutil.copy2(myfile,r'D:\foo.ogg')


Krzysztof's idea was excellent, because the quotation marks *are* the
source of the problem. I don't know why, and maybe it should be
considered a bug on Windows (note I don't say *in* Windows or *in*
Python, because it could be either), but I can get the same behaviour
by creating a file manually on Linux and then trying to access it
through a file share from Windows. In the following, drive G: is
my Samba-shared drive:

G:\>python
>>> import os
>>> os.path.isfile('This is a "test" file')

True
>>> os.path.isfile('This is a "test" filex') # just testing

False
>>> import shutil
>>> shutil.copy('This is a "test" file', r'c:\test.txt')

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:\a\python23\lib\shutil.py", line 71, in copy
copyfile(src, dst)
File "c:\a\python23\lib\shutil.py", line 37, in copyfile
fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: 'This is a "test" file'


Perhaps your only option for now, since it seems shutil.copy
uses the underlying OS copy and that barfs on Windows, is to
open the file and copy it the hard way:

>>> data = file('This is a "test" file').read()

Traceback (most recent call last):
File "<stdin>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'This is a "test" file'


Ouch! That doesn't work either.

Okay, any reason not to call this a bug in the Windows version of
Python, when os.path.isfile can handle the name but Python can't
open or copy the file?


Note that os.listdir() on my machine shows the 8.3 format name
even though apparently on Stephen's CD it does not:

>>> os.listdir('.')

['peter', 'im', 'THISI~LT', 'quicken.old']

(Stephen, I think therein lies your solution for now though, which
is to find the 8.3 format name with, say, "DIR /x" or maybe
win32api.GetShortPathName (if that even works) and copy it that
way.)

-Peter
 
Reply With Quote
 
Krzysztof Stachlewski
Guest
Posts: n/a
 
      04-16-2004
Stephen Boulet wrote:

> I'm on win2000. The file is on a CD I burned, and I wanted to copy it to
> a file name that doesn't have any quotation marks in it. The problem is
> that I can't reference the file to begin with. The command:
>
> shutil.copy2(myfile,r'D:\foo.ogg')
>
> can't use the string held in myfile, although os.listdir('directory on
> CD') contains it as the first entry.
>
> It would be nice if I could referene the file in a way that would not
> cause the copy command to fail.


Its not a problem with Python, but with the CD-burning software
which allowed for the illegal char in the filename.
Can you open the file using Explorer? Or move it to disk and rename?
That's the best thing you can do about it.

--
Stach Tlen: stachobywatelpl, GG: 1811474
Jabber: stach at jabber atman pl
 
Reply With Quote
 
Stephen Boulet
Guest
Posts: n/a
 
      04-16-2004
Peter Hansen wrote:

> Okay, any reason not to call this a bug in the Windows version of
> Python, when os.path.isfile can handle the name but Python can't
> open or copy the file?


Good question.

> (Stephen, I think therein lies your solution for now though, which
> is to find the 8.3 format name with, say, "DIR /x" or maybe
> win32api.GetShortPathName (if that even works) and copy it that
> way.)
>
> -Peter


I can list the file at the DOS prompt:

"dir /x" gives me "01SYMP~2.OGG" as the short file name, "dir
01SYMP~2.OGG" does echo back the file name, but "copy 01SYMP~2.OGG"
gives me a "The system cannot find the file specified" error.

Oh well, I'll just redo it with a different file name.

I did burn the CD under linux, with k3b as a front end to cdrecord,
using joliet extensions with 128 character file names enabled.

Stephen
 
Reply With Quote
 
Krzysztof Stachlewski
Guest
Posts: n/a
 
      04-16-2004
Peter Hansen wrote:

> Okay, any reason not to call this a bug in the Windows version of
> Python, when os.path.isfile can handle the name but Python can't
> open or copy the file?


Hmmm... isfile() apparently uses some OS functions that don't
check for valid characters in filenames.
If it is a bug then it is a bug within Windows.
But from the Windows point of view, a " in filename
is simply some piece of corrupted data so it can do anything with it.
It's good it doesn't display BSOD.

--
Stach Tlen: stachobywatelpl, GG: 1811474
Jabber: stach at jabber atman pl
 
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
Error copying file or folder itsecurityguy@gmail.com Computer Support 3 04-30-2008 11:21 PM
error copying file or folder =?Utf-8?B?cGFuZWh5aW90aXM=?= Windows 64bit 3 04-04-2007 04:55 PM
Error when copying file Ryan Chen Windows 64bit 1 03-28-2006 05:58 PM
Help copying file from homemade DVD - Data error message Arawak Computer Support 1 10-06-2004 01:27 PM
Re: System.IO.File.Copy not copying and no error David Waz... ASP .Net 1 07-07-2003 06:18 AM



Advertisments