如何立即创建文件夹(如os.makedirs公司()在程序完成后创建文件夹)?

2024-03-28 19:18:35 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想在我的程序还在运行的时候创建一个文件夹,因为在我创建它之后,我需要一些文件放进去。你知道吗

我意识到它不是立即创建的,我也想问为什么会发生这种情况。你知道吗

我也得到这个错误

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\NemPl\\Desktop\\ProLan\\Python\\Python programi\\user.NemPlayer\\pass.asd123ASD'

编辑:

以下是源代码,它不会立即显示我的文件夹:

import re
import urllib.request
import os.path

print("------PROFILE CREATOR------")
print()
while True:
    breakLoop = 0
    notCorrect = ""
    correct = 0
    profileName = input("Username: ")
    if profileName == "":
        print("Your username can't be blank!")
        continue
    elif os.path.isdir("user." + profileName):
        print("Username taken!")
        continue
    else:
        pass
    for n in profileName:
        if re.search(r" ", profileName):
            notCorrect += "...can't contain spaces!\n"
        if notCorrect == "":
            breakLoop = 1
            break
        else:
            print("Your username...")
            print(notCorrect)
            break
    if breakLoop == 1:
        os.makedirs(r'C:\Users\NemPl\Desktop\ProLan\Python\Python programi\user.' + profileName)
        break
    else:
        pass
while True:
    notCorrect = ""
    breakLoop = 0
    profilePassword = input("Password: ")
    if profilePassword == "":
        print("Your password can't be blank!")
        continue
    else:
        pass
    for n in profilePassword:
        if re.search(r' ', profilePassword):
            notCorrect += "...can't contain spaces!\n"
        if not re.search(r'\d', profilePassword):
            notCorrect += "...has to contain at least one number!\n"
        if not re.search(r'[a-z]', profilePassword):
            notCorrect += "...has to contain at least one lowercase letter!\n"
        if not re.search(r'[A-Z]', profilePassword):
            notCorrect += "...has to contain at least one uppercase letter!\n"
        if notCorrect == "":
            breakLoop = 1
            break
        else:
            print("Your password...")
            print(notCorrect)
            break
    if breakLoop == 1:
        filePassword = open(r"C:\Users\NemPl\Desktop\ProLan\Python\Python programi\user." + profileName + "\pass." + profilePassword)
        break
    else:
        pass

Tags: researchyourifpasscanelseprint
1条回答
网友
1楼 · 发布于 2024-03-28 19:18:35

它是“没有这样的文件或目录”错误的“没有这样的文件”端。您需要包括“w”写入模式来创建文件。你知道吗

filePassword = open(r"C:\Users\NemPl\Desktop\ProLan\Python\Python programi\user." + profileName + "\pass." + profilePassword, "w")

相关问题 更多 >