I want to read the specific text file by giving only its name(not full path) from the folder containing multiple sub-directories, in order to compare and merge the text files.
How to can I read the specific file using pandas ?
You can use walk to search for the file and then work with it
import os
name = "Name of your file"
root= './' #Assuming you will search from current directory, you can give any path = []
for dirpath, subdirs, files in os.walk(root):
for x in files:
if x==name:
path.append(os.path.join(dirpath, x))
print(path) #do your operation here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.