
- #Python list directory contents and modified date how to#
- #Python list directory contents and modified date code#
Print join(root, name), modification_date(join(root, name)), creation_date(join(root, name))ĭepending on your particular commandline parameters implementation you want to convert what's passed on commandline to a unix timestamp and compare with either of the dates.
#Python list directory contents and modified date code#
If you prefer to do it with shell, then find is your friend, with the following flags:įile's status was last changed n*24 hours ago.įile's data was last modified n*24 hours ago.Ī small code example to get modification time of files in a given dir ("."): import os

Print "created: %s" % time.ctime(os.path.getctime(file)) Print "last modified: %s" % time.ctime(os.path.getmtime(file)) One option would be to use something in lines of os.walk and filter out files based on ctime/mtime, which you can get like this: import os.path, time
#Python list directory contents and modified date how to#
and then get all files that are modified/created between those dates. How to Get the Modified Time of a File using Python MaYou can use the following template to get the modified time of a file using Python: import os.path modifiedtime os.path.getmtime (rpath where the file is storedfile name. Regardless of the method, the user should input two dates: start and end. I know that certain features dont work exactly in Linux and Windows, so help on this matter would be warranted. What must I put in that command to get these file names?Ĭonversely - it does not have to be a command, if it can be done using pure code, such as os.walk for instance, that is also great. Help = "the ending date of the files to search")įile_names = command("get files that match dates command") Parser.add_option("-e", "-enddate", dest = "enddate",\ Help = "the starting date of the files to search") Parser.add_option("-s", "-startdate", dest = "startdate",\ Shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) The relevant code so far: #! /usr/bin/env python I do not know much about linux and I would like to know what command I can use to get a list of files in a directory that match within a date range I specify.Īlso, what is the correct formating for this type of query, as this process will be automated and the user needs to just put in his start and end dates.


I am trying to write code that will fetch the files in a directory that have been created/modified within a specific date range.
