python - glob.iglob Remove path from filename -
i trying recent file added directory using python 2.7 os , glob modules.
import os import glob path = "files/" newestfile = max(glob.iglob(path + '*.txt'), key=os.path.getctime) print newestfile when print newestfile variable path included i.e.
files\file.txt
i want filename .txt file , .py script not in same directory. text file 1 directory down under files directory. how refer directory , newest .txt file added directory.
you can use os.path.basename filename:
newestfile = os.path.basename(max(glob.iglob(path + '*.txt'), key=os.path.getctime)) os.path.getctime going need full path 1 way or have use full path.
Comments
Post a Comment