1

I'm writing a script to download a file from a website, and I'm able to successfully save the file using a path entered into the code, however if I use an input then things don't work.

path = input("Save Location: ")

From here I'll use os.path.join to append the file type to the end of the path and then use PycURL to download the file. But getting a user input for the path gives a FileNotFoundError, for example C:/Users/MyName/Desktop become C:UsersMyNameDesktop/v.mp4 after appending the file type. I've also tried C:\\Users\\MyName\\Desktop as well as C:\/Users\/MyName\/Desktop however they give the same thing, and ideally I'd like to avoid using double forward/back slashes in the input since they're not very user friendly.

If for whatever reason you need any more code/all the code don't hesitate to ask. Thanks :)

1
  • show your code with os.path.join and C:/Users/MyName/Desktop Commented Jan 24, 2016 at 18:32

1 Answer 1

1

try to use https://docs.python.org/3/library/os.path.html#os.path.normpath

>>> x = input()
C:/Users/MyName/Desktop
>>> os.path.normpath(os.path.join(x, 'v.mp4'))
'C:\\Users\\MyName\\Desktop\\v.mp4'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I did something very similar to this but this seems to work. Not sure why mine didn't but hey. This one does :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.