8000 GitHub - andrzejQ/filedate: Simple, convenient and cross-platform file date changing library. πŸ“…
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

andrzejQ/filedate

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

γ€€

Description πŸ“

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

Forked from kubinka0505/filedate

See also jelmerwouters / filedate -> FileDate.set() (not tested here, commented)

Installation πŸ–₯️

  • git or get source files
git clone git://github.com/andrzejQ/filedate
cd filedate
python -m pip install -e ./Files

-e installs the package in editable mode. Any changes you make to the code in local folder will immediately apply across the system.

Source can be also used without installation.

Usage πŸ“

  • see doctest examples
from filedate import FileDate

# Create filedate object
file_date = FileDate('__init__.py')

# Get file date
file_date.get() 
# {'created': datetime.datetime(20..,... 'modified': ... 'accessed': ...}
print(file_date) # .get(); __str__()
# {'created': '20..

# Set file/folder date
file_date.set(
  created = "01.02.2000 12:00",
  modified = "2001/03/04",
  accessed = "2001-05-06")
# {'created': '2000-02-01 12:00:00', 'modified': '2001-03-04 00:00:00', 'accessed': '2001-05-06 00:00:00'}
file_date.set( 
  created = "01.02.2000 12:00", 
  modified = "3:40PM 2001/03/04", 
  accessed = "5rd March 2002 20:21:22"
)
# {'created': '2000-02-11 12:00:00', 'modified': '2001-04-03 15:40:00', 'accessed': '2002-03-05 20:21:22'}

Copy file dates from one to another πŸ”ƒ

  • for [c]reated, [m]odified, [a]ccessed date
from filedate.utils import CopyFileDate
CopyFileDate("../__init__.py", "rec_20210911 134705.abc.txt").set_date('cma')

Keeping files dates βŒ›

from pathlib import Path
from filedate.utils import KeepFileDate

# Get all files in subdirectories (recursive!)
Files = []
for File in Path(".").glob("**/*"):
	Files.append(File)

#---#

# Initialize `Keep` object
Dates = KeepFileDate(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()
  1. Once we have the backup, we can restore files/folders dates using
    "copyAllDatesFromDir_recursive.py" (see examples, see also "TCommanderMenu_2023-04.txt")

Set file dates based on its name πŸ“

  • for [c]reated, [m]odified, [a]ccessed date
from filedate.utils import FromFileName
FromFileName("rec_2020-09-11 13.47.05.abc.txt").set_date('cma')

see also examples in _yyyy_() and _dd_MM_yyyy_()

Set file dates based on its metadata πŸ“

  • for [c]reated, [m]odified
from filedate.utils import FromMetadata
FromMetadata(file_path).set_date('cm'))  # or 'm'

Working examples

  • Files\examples\ setDatesFromNames_recursive.py
    -> Get all files/folders in subdirectories (recursive) and set their dates based on file name.
  • Files\examples\ setFolderDates_recursive.py
    -> Set date of folder (recursive) based on dates of files/folders below it - iterative from child directories first.
  • copyAllDatesFromDir_recursive.py
  • setDateFromName.py
  • copyFileDate.py
  • setDateFromMetadata.py (pip install PyPDF2 hachoir required)
  • setDatesFromMetadata_recursive.py

About

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

Resources

License

4DEC

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%
0