Skip to content

Simple, convenient and cross-platform file date changing library. πŸ“…

License

Notifications You must be signed in to change notification settings

kubinka0505/filedate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

γ€€

γ€€γ€€

Description πŸ“

Simple, convenient and cross-platform file date changing library. πŸ“…

Installation πŸ–₯️

  1. git (recommended)
git clone https://github.com/kubinka0505/filedate
cd filedate/Files
python setup.py install
  1. pip
python -m pip install "git+https://github.com/kubinka0505/filedate#egg=filedate&subdirectory=Files" -U --use-deprecated=legacy-resolver

Important

If on macOS, requires SetFile utility coming with xcode in order to set files creation time.

xcode-select –-install

Warning

Importing cli_core will close the console.

Caution

Due to the internal Python bug and the year 2038 problem, commented actions in this range of code are impossible to execute.

ℹ️ Please visit this StackOverflow answer for more information.

Usage πŸ“

Module

import filedate

# Create filedate object
File = filedate.File("~/Desktop/File.txt")

# Get file date
File.get()

# 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

# Individual types
input_file = filedate.File("~/Desktop/Input.mp4")
output_file = filedate.File("~/Desktop/Output.mp4")

output_file.created = input_file.created 
output_file.modified = input_file.modified
output_file.accessed = input_file.accessed

#-=-=-=-#

# Legacy
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
)

Command-line console script

user$os:~ $ # Set file dates
user$os:~ $ filedate -i "~/Desktop/File.txt" -c "01.01.2000 12:00" -m "3:30 PM 2001/02/02" -a "3rd March 2002 20:00:30"
user$os:~ $ 
user$os:~ $ # Get file dates (simple)
user$os:~ $ filedate -i "~/Desktop/File.txt"
Created:  01/01/2000 12:00:00
Modified: 02/02/2001 15:30:00
Accessed: 03/03/2002 20:00:30
user$os:~ $ 
user$os:~ $ # Get file dates (expanded)
user$os:~ $ filedate -i "~/Desktop/File.txt" -e
Created:  Saturday, 01st January 2000, 12:00:00.000000
Modified: Friday, 02nd February 2001, 15:30:00.000000
Accessed: Sunday, 03rd March 2002, 20:00:30.000000