无法使用Python pathlib在特定文件夹中创建新目录

时间:2018-11-03 21:18:58

标签: python-3.x directory subdirectory pathlib

我一直在浏览互联网和文档两天,试图弄清楚这一点。我正在尝试创建一个脚本,该脚本在运行时会提示输入字符串,然后使用该字符串在特定目录中创建一个文件夹。我已经对其进行了很多更改,遇到了许多不同的错误,当我没有收到错误时,什么也没有发生,或者该文件夹在我想要的目录之外创建。

我终于转向堆栈溢出;指导手会很有帮助。

def CreateStory():
'''
Creates a story folder in AdventureMaker>Stories named with the story title, 
and creates a single page in that story
'''
story = input('What will you name your story?\n')
stories.append(story)

    if Path('C:/Documents/Code/AdventureMaker/Stories/' + story).exists():

        print('There is already a story with that name!')
        #prompt to add a new page to the story instead, or to try a new name

    else:

        #create a folder with the story title, then move on to creating the 
        first page
        Path('C:/Documents/Code/AdventureMaker/Stories/' + story).mkdir()

0 个答案:

没有答案