To set the path to the current folder and a text folder in it, we can use the os
module in Python for file handling.
First, we need to import the os
module:
main.py10 chars2 lines
Then, we can use the os.getcwd()
function to get the current working directory:
main.py32 chars2 lines
Next, we can use os.path.join()
function to join the current directory with the text folder name to get the path of the text folder:
main.py54 chars2 lines
Now we can use text_folder
variable to access the files inside the text folder.
Here's the final code block:
main.py277 chars10 lines
gistlibby LogSnag