1

I have a program that needs a file to send over a socket, but I'm not sure how to get the file from the user. I was thinking something like this:

file_direc = input("Please enter the directory of the file: ")
f = open(file_direc, "r")

but I'm not sure how to access the user's directory. Is there any way to do this?

  • 1
    What's wrong with this approach, but just asking directly for the file? – Ted Klein Bergman Jan 04 '21 at 15:45
  • Or, if you're just asking how to get all files in a directory, then there are many similar questions: https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory, https://stackoverflow.com/questions/21384232/how-to-get-only-files-in-directory?noredirect=1&lq=1,https://stackoverflow.com/questions/37489280/python3-list-files-from-particular-directory?noredirect=1&lq=1, – Ted Klein Bergman Jan 04 '21 at 15:50
  • https://stackoverflow.com/questions/120656/directory-tree-listing-in-python?noredirect=1&lq=1, https://stackoverflow.com/questions/11968976/list-files-only-in-the-current-directory?noredirect=1&lq=1, https://stackoverflow.com/questions/16015955/reading-all-files-in-all-directories?noredirect=1&lq=1, https://stackoverflow.com/q/19587118/6486738, https://stackoverflow.com/questions/973473/getting-a-list-of-all-subdirectories-in-the-current-directory, https://stackoverflow.com/questions/31049648/how-to-get-list-of-subdirectories-names/31049721 – Ted Klein Bergman Jan 04 '21 at 15:50
  • Does this answer your question? [How do I list all files of a directory?](https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory) – Ted Klein Bergman Jan 09 '21 at 05:17

0 Answers0