Error copying a file

S

Stephen Boulet

I know that the name of this file is somewhat pathological, but this if
weird:
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
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'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
 
K

Krzysztof Stachlewski

Stephen said:
I know that the name of this file is somewhat pathological, but this if
weird:

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.
 
S

Stephen Boulet

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

Peter Hansen

Stephen said:
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:\>pythonTraceback (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:
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:
['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
 
K

Krzysztof Stachlewski

Stephen said:
> 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.
 
S

Stephen Boulet

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

Krzysztof Stachlewski

Peter said:
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. ;-)
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top