5
Hello,
I am creating a code that should check if a folder exists, if it does not exist the code should create it and then proceed, otherwise it just goes with the flow.
I tried with If and While but I was not successful. Most of the time it creates the folder I want but returns me the error "Could not create an existing folder". For this to happen there must be a loop that I’m not able to identify, can help me?
Follow the two forms I tried below:
MODE 1:
if username and password != None:
while os.path.exists('C:\ Backup') == False:
makedirs("C:\ Backup\ ")
if os.path.exists('C:\ Backup') == True:
break
else:
print "nao foi possivel logar"
#for ip in radius:
#gravar = open(ip+".txt", "w")
#gravar.write("Configuração")
#gravar.close()
MODE 2:
if username and password != None:
if pass os.path.exists('C:\ Backup') == False:
makedirs("C:\ Backup\ ")
else:
for ip in radius:
gravar = open(ip+".txt", "w")
gravar.write("Configuração")
gravar.close()
else:
print "nao foi possivel logar"
PS: Maybe it’s something simple that I couldn’t identify, I don’t have much experience with programming but I’m trying to improve. So, i’m Sorry.
Thank you!
Thanks Miguel, you helped me a lot!
– Cristhian Miguel
You’re welcome @Cristhianmiguel. I’m glad you decided
– Miguel