FAQ
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!

Search Discussions

  • Tim Golden at Aug 12, 2010 at 12:11 pm

    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
  • Aleksey at Aug 12, 2010 at 1:16 pm

    On 12 ???, 18: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.

    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.
  • Drodrig at Aug 17, 2010 at 6:03 pm

    On Aug 12, 9:16?am, Aleksey wrote:
    On 12 ???, 18:49,drodrigwrote:
    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.
    (Sorry for the late reply)

    Thank you. The questions marks are indeed placeholders for unprintable
    characters. The glob module did the trick.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 12, '10 at 11:49a
activeAug 17, '10 at 6:03p
posts4
users3
websitepython.org

3 users in discussion

Drodrig: 2 posts Aleksey: 1 post Tim Golden: 1 post

People

Translate

site design / logo © 2022 Grokbase