Python/Discord当我试图创建一个文件夹时,它位于我的桌面上,而不是指定的文件夹中

2024-06-16 08:35:46 发布

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

这是当前代码:

   if message.content == "MMO start":
        dir=(r"C:\\Users\\User\Desktop\MMMOProfiles")
        file = str(message.author)
        path = os.path.join(dir,file)
        isExist = os.path.exists(path)
        if isExist == True:
            await message.channel.send("You already have a profile")
        elif isExist == False:
            await message.channel.send("Creating profile")
            file2 = str(message.author)
            dir =(r"C:\\Users\\User\Desktop\MMOProfiles")
            os.mkdir(file2)

当我试图让它创建文件夹,虽然它在桌面上,而不是在桌面上的文件夹


Tags: pathsendmessageifosdirchannelawait
1条回答
网友
1楼 · 发布于 2024-06-16 08:35:46

此代码将检查桌面中的文件夹是否存在,如果没有,将创建新文件夹:

newpath = r'C:\Users\mooqa\Desktop\ss' 
if not os.path.exists(newpath):
os.makedirs(newpath)

相关问题 更多 >