Answer the question
In order to leave comments, you need to log in
How to write an if condition?
Tell me, you need to create directories, how to make a condition so that if returns false if the directory exists, in order to immediately call mkdir (), without else ?
An instruction like != Doesn't work for me, I don't know how to apply it, or is there another way?
To create directories, if one already exists, then display a message and work further (add Files to this directory)
if os.path.exists(path):
print ('Каталог существует')
else:
os.mkdir(path)
Answer the question
In order to leave comments, you need to log in
import os
name = input("Folder name: ")
try:
....os.mkdir(name)
except OSError:
........print("Folder named "+name+" already exists")
Instead of . space
After the Exception processes the request and the folder already exists, it will write that such a folder with Name () has already been created and the folder will not be overwritten !!!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question