10

Windows 7, python 2.6.6, 2.7

Create directory 'c:\1\test.'

Try check if it is dir or file, but it is neither:

>>> os.listdir('c:/1')
['test.']
>>> os.path.isdir('c:/1')
True
>>> os.path.exists('c:/1/test.')
False
>>> os.path.isdir('c:/1/test.')
False
>>> os.path.isfile('c:/1/test.')
False

Why directory with . at end not recognized as file system entry at all? But I can obtain it from os.listdir.

4
  • Can't reproduce. How did you create this directory? My Windows 7 (32 bit) strips the dot, no matter whether I use mkdir or the explorer, I always end up with test. os.listdir confirms this (['test']). os.isdir returns True for both test (and for test., presumably because the dot is stripped there as well) and os.isfile returns False as expected.
    – user395760
    Mar 26, 2011 at 11:28
  • I am create it with Far. Also it can be created with cygwin/mkdir. Mar 26, 2011 at 11:30
  • Windows has problems with such filenames in general. For example, you can't navigate into the directory or delete it in Explorer.
    – interjay
    Mar 26, 2011 at 11:38
  • I see... So, I think this is not problem for my program. Users usually can't create such directories, only geeks like me :) Thanks Mar 26, 2011 at 11:50

1 Answer 1

6

As was said in the comments, on Windows, file names that end with a dot, begin/end with spaces, are "aux", etc. etc. etc. - cannot be accessed normally from explorer or from most programming languages.

If you do want to access directories such as "test." from python (or other) code, you can prefix the path with \\?\, for example:

>>> os.path.isdir(r"\\?\c:\1\test.")
True

Note that ".." and "." will not work as usual when using \\?\ paths - windows will try to access an actual file or directory with that name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.