Conclusion
os.listdir(path)
It all started when I wanted to list the documents in Downloads.
Examine the path
#Method 1 option+command+C
#On Mac, you can get "absolute PATH" by pressing "option", "command", and "C" while selecting a file.
#Example:/Users/"User name"/Downloads/"File name"'
#Method 2
#Search for file names
#During study
Get files and folders with listdir
#This time, get the Downloads data
import os
path = '/Users/username/Downloads'
files = os.listdir(path)
for file in files:
print(file)
extension(.pdf)I want to check the file name by specifying
import glob
path = '/Users/username/Downloads'
print(glob.glob(path+'/*.pdf'))
If you want to search only now
Current directory
import os
print(os.getcwd())
For example, I'm writing python in spyder, so
/Users/username/.spyder-py3
Will be returned.
Specify extension
import glob
glob.glob('*.py')
In the /Users/username/.spyder-py3 file
untitled0.py temp.py template.py history_internal.py history.py
Was returned when it was included.
Click here for convenient usage of glob How to use glob to recursively get a list of paths that satisfy the conditions in Python