#EX38.PY Get listing of all files in a directory #http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python # Answer 37 import os, datetime topDir = "C:/BrcmCDs" dateFirst = True # put dates before file names # DateFirst = False # put file names before dates def modDate(fileN): # returns a 10-place date string t = os.path.getmtime(directory+"/"+fileN) return str(datetime.datetime.fromtimestamp(t))[0:10] for directory, dirnames, filenames in os.walk(topDir): outList = [] print "Directory: ", directory print for fileA in filenames: if (fileA[0:10] == "B57IBMCD_T" and fileA[-4:] == ".zip"): dateString = modDate(fileA) if dateFirst: fileString = dateString + " " + fileA else: fileString = fileA + " " + dateString outList.append(fileString) # outList.sort() # sort the file list, assending outList.reverse() # reverse the file list, desending print outList #show all files # now save list to a file: # https://bbs.archlinux.org/viewtopic.php?id=75839 f = open("fileList.TXT", "w") f.write("\n".join(map(lambda x: str(x), outList))) f.close()

AltStyle によって変換されたページ (->オリジナル) /