python递归遍历路径下的所有文件和文件夹
import os
def file_listen(path):
path = path + "/"
first_dir_list = os.listdir(path)
#print("the path( "+ path,"):",first_dir_list)
#print("exist file:", files)
new_file = [file for file in first_dir_list if os.path.isfile(path + file)]
if new_file:
print("new file:",new_file)
#files.extend(new_file)
dirs = [str(path +file) for file in first_dir_list if os.path.isdir(path + file)]
if dirs:
print("new dirs:",dirs)
for dir in dirs:
file_listen(dir)
import os
import time
filename = "myTex.txt"
folder1 = "/media/B/01-workspace/spaDev_v5/bps3.0/project"
folder2 = "/media/B/01-workspace/spaDev_v5/bps3.0"
info = os.stat(os.path.join(folder1,filename))
info2 = os.stat(os.path.join(folder2,filename))
if info2.st_mtime != info.st_mtime:#10分钟
print("modify")
else:
print("done")