2

I tried to create a directory with os.mkdir, but it raised FileExistsError.

>>> import os
>>> os.mkdir('test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileExistsError: [Errno 17] File exists: 'test'

The file test does exist, but it is a regular file instead of a directory.

  0 -rw-r--r--  1 sparkandshine  staff       0 Jan 31 17:09 test

How do I create a directory test/ in this case?

SparkAndShine
  • 17,001
  • 22
  • 90
  • 134

2 Answers2

4

Operating systems do not allow files and directories with the same name. A directory is simply a special type of file.

See the following for more information: https://unix.stackexchange.com/questions/22447/why-cant-i-have-a-folder-and-a-file-with-the-same-name

Community
  • 1
  • 1
Jake Sebright
  • 799
  • 8
  • 16
2

You can't have a file and a directory named the same thing. If you had the file called test.txt or something it would work

~> touch test
~> mkdir test
mkdir: test: File exists
quikst3r
  • 1,783
  • 1
  • 10
  • 15