demand
It is required to find the word documents in a certain date range in the folder, and list the names and paths of all words, such as all word documents under the D drive from July 5 to July 31.
Modify file type
Modify file path
Retrieve file modification time interval
#conding=utf8 import os import time g = os.walk(r"C:\Users\Administrator\Downloads") def judge_time_file(path, file, update_time): if not file.endswith(('.doc','.docx')): return False start_time = time.mktime(time.strptime('2020-04-12 00:00:00', "%Y-%m-%d %H:%M:%S")) end_time = time.mktime(time.strptime('2020-05-23 00:00:00', "%Y-%m-%d %H:%M:%S")) # print(start_time , update_time , end_time) if start_time < update_time < end_time: return True return True data_list = [] i = 0 for path, dir_list, file_list in g: for file_name in file_list: local_time = os.stat(os.path.join(path, file_name)).st_mtime if judge_time_file(path, file_name, local_time): data_list.append([os.path.join(path, file_name), time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(local_time))]) # print(data_list) i=i+1 print(i) data_list.sort(key=lambd
Read More:
- Python recursively traverses all files in the directory to find the specified file
- The Python DOM method iterates over all the XML in a folder
- Python automatically generates the requirements file for the current project
- Change the Python installation path in Pycharm
- Python classes that connect to the database
- You can run the Ansible Playbook in Python by hand
- Python: How to Reshape the data in Pandas DataFrame
- Python+ Pandas + Evaluation of Music Equipment over the years (Notes)
- python: File Processing and Input and Output
- Python: SVN deletes files on local and remote repositories
- Python Time Module timestamp, Time string formatting and Conversion (13-bit timestamp)
- Linux installs Python and upgrades Python
- Record Stanford corenlp running all the time without error
- Python: How to Use os.path.join()
- Python time tuples are converted to timestamps, strings
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- Python: How to Delete Empty Files or Folders in the Directory
- Python errors: valueerror: if using all scalar values, you must pass an index (four solutions)
- Python 3 uses the relative path import module
- [Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed