modules if we need several pieces of information about file or directory we can use os stat()but if we need just one piecewe can use the relevant os path functionfor exampleos path exists()os path getsize()os path isfile()or os path isdir(the mimetypes module has the mimetypes guess_type(function that tries to guess the given file' mime type examplethe os and os path modules here is how we can use the os and os path modules to create dictionary where each key is filename (including its pathand where each value is the timestamp (seconds since the epochwhen the file was last modifiedfor those files in the given pathdate_from_name {for name in os listdir(path)fullname os path join(pathnameif os path isfile(fullname)date_from_name[fullnameos path getmtime(fullnamethis code is pretty straightforwardbut can be used only for the files in single directory if we need to traverse an entire directory tree we can use the os walk(function here is code snippet taken from the finddup py program the code creates dictionary where each key is -tuple (file sizefilenamewhere the filename excludes the pathand where each value is list of the full filenames that match their key' filename and have the same file sizedata collections defaultdict(listfor rootdirsfiles in os walk(path)for filename in filesfullname os path join(rootfilenamekey (os path getsize(fullname)filenamedata[keyappend(fullnamefor each directoryos walk(returns the root and two listsone of the subdirectories in the directory and the other of the files in the directory to get the full path for filename we need to combine just the root and the filename notice that we do not have to recurse into the subdirectories ourselves--os walk(does that for us once the data has been gatheredwe can iterate over it to produce report of possible duplicate filesa much more sophisticated find duplicates programfindduplicates- pywhich uses multiple threads and md checksumsis covered in