Copying a file with a question mark in it's name in Windows

Aleksey alekseymv at
Thu Aug 12 15:16:02 CEST 2010

On 12 авг, 18:49, drodrig <drod... at> 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.

More information about the Python-list mailing list