Simple, convenient and cross-platform file date changing library. π
git
(recommended)
git clone git://github.com/kubinka0505/filedate
cd filedate/Files
python setup.py install
Tip
You can alse use this ugly one-liner for most recent commits:
python -m pip install "git+https://github.com/kubinka0505/filedate#egg=filedate&subdirectory=Files" -U --use-deprecated=legacy-resolver
python -m pip install filedate -U
import filedate
# Create filedate object
File = filedate.File("~/Desktop/File.txt")
# Get file date
File.get_dates()
# Alternatives
dir(File)
File.created, File.modified, File.accessed
# Set file date
File.created = "01.01.2000 12:00"
File.modified = "3:30PM 2001/02/02"
File.accessed = "3rd March 2002 20:00:30"
# Legacy
File.set(
created = "01.01.2000 12:00",
modified = "3:30PM 2001/02/02",
accessed = "3rd March 2002 20:00:30"
)
Copy file dates from one to another π
import filedate
filedate.copy(
"~/Desktop/Input.mp4", "~/Desktop/Output.mp4",
created = True,
modified = True,
accessed = True
)
Keeping files dates β
import filedate
from pathlib import Path
# Get all files in subdirectories (recursive!)
Files = []
for File in Path(".").glob("**/*"):
File = str(File.resolve())
Files.append(File)
#-=-=-=-#
# Initialize `Keep` object
dates = filedate.utils.Keep(Files)
# Pick dates
dates.pick()
# ... Do your stuff ...
#
# from os import system
# for File in Files:
# system(f'optimize -i "{File}"')
# Drop dates
dates.drop()
Set file dates based on its name (beta) π
from filedate import utils
utils.set_from.file_name(
"~/Downloads/20200919_134705.wav",
created = True,
modified = False,
accessed = True,
)