From: drodrig on
A python script I use to backup files on a Windows 2003 server
occasionally fails to retrieve the size of a file with a question mark
in the name. The exception I get is "OSError #123 The filename,
directory name, or volume label syntax is incorrect". I realize that
technically a question mark in the name of a file on Windows is
illegal, but nevertheless these files exist on the file system. It
seems that they are created by Office 2007 Word, for the most part.

The line that fails is:

os.path.getsize(source)

Where source is the full path to the file with the question mark in
it's name.

Any idea how to retrieve the file's size? Also, I imagine that after I
overcome this hurdle, I'll need help finding a way to copy the file
(assuming copy2() doesn't work). I've tried escaping the question mark
("\\?"). Same result.

Although I could use the Windows "dir" command, parsing the results to
find the size of the file then use the Windows "copy" command, I'd
rather stay away from this type of solution.

Any help is appreciated!

From: Tim Golden on
On 12/08/2010 12:49, drodrig wrote:
> A python script I use to backup files on a Windows 2003 server
> occasionally fails to retrieve the size of a file with a question mark
> in the name. The exception I get is "OSError #123 The filename,
> directory name, or volume label syntax is incorrect". I realize that
> technically a question mark in the name of a file on Windows is
> illegal, but nevertheless these files exist on the file system. It
> seems that they are created by Office 2007 Word, for the most part.

Could you show us the script you're using? I'm not aware of any
way to get a question mark into a file name; even using the
file namespace prefix \\?\ doesn't allow it as far as I can tell.

Where are you seeing the question mark? Is it possible it's a
placeholder for an unprintable character rather than an actual
question mark?

TJG
From: Aleksey on
On 12 авг, 18:49, drodrig <drod...(a)magicbrain.com> wrote:
> A python script I use to backup files on a Windows 2003 server
> occasionally fails to retrieve the size of a file with a question mark
> in the name. The exception I get is "OSError #123 The filename,
> directory name, or volume label syntax is incorrect". I realize that
> technically a question mark in the name of a file on Windows is
> illegal, but nevertheless these files exist on the file system. It
> seems that they are created by Office 2007 Word, for the most part.


If "?" is a placeholder for an unprintable character you can try view
real file name in IDLE:

import glob
print glob.glob(u'e:/full/path/to/file?')

In path to file you must instead question use wild "?".
Will be printed all like files.

-----------------------------
Under Windows I too have similar problem: windows sometimes (from any
programs - e.g. Firefox) save files with wrong names, but later
do not manipulate with it.