1

I've been poring over the internet and the documentation for about two days now trying to figure this out. I'm trying to create a script that, when run, prompts for a string and then creates a folder in a specific directory using that string. I've changed it a lot, gotten numerous different errors, when I don't get an error nothing happens or the folder is created outside of the directory I'm aiming for.

I've finally turned to stack overflow; a guiding hand would be very helpful please.

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()
  • Does `Path(...).mkdir(parents=True)` work? – Aran-Fey Nov 03 '18 at 21:21
  • What name are you attempting? Not all characters are allowed in folder names. – Jongware Nov 03 '18 at 21:23
  • start by fixing your identation? – Patrick Artner Nov 03 '18 at 21:42
  • @Partick Artner Sorry about that, the indentation is fine in code. I tried to figure out stack overflow's formatting quirks. – WatcherMagic Nov 03 '18 at 21:59
  • @usr2564301 the name is just 'Story' – WatcherMagic Nov 03 '18 at 22:04
  • @Aran-Fey when using parents=True the first part of the if statement executes, though when I search manually I can't find any folders with that name, especially with that specific path. – WatcherMagic Nov 03 '18 at 22:04
  • What if you change `"C:/"` to `"C:\\"`? – Aran-Fey Nov 03 '18 at 22:05
  • @Aran-Fey: theoretically that should [not be a problem](https://stackoverflow.com/q/2953834/2564301). My next bet is part of the path does not exist. – Jongware Nov 03 '18 at 22:08
  • I've done some more fiddling, and actually managed to find the path that I was missing: turns out I needed a 'C:/Users/myname/Documents/etc', I was trying to use the Documents shortcut that shows up outside of C: (whoops). Which leads me to this, how do I reference the computer's users in pathlib without hardcoding? Thanks to all who've helped so far! – WatcherMagic Nov 04 '18 at 16:09
  • Hah, so I wuz right! As to your new (slash revised) question, I happened to have answered exactly that just the other day: https://stackoverflow.com/a/53068227/2564301 – Jongware Nov 04 '18 at 20:30
  • @usr2564301 You were! Congratulations, and thank you as well! – WatcherMagic Nov 04 '18 at 22:38

0 Answers0