Git Product home page Git Product logo

date2name's Introduction

Handling time-stamps and date-stamps in file names

bin/screencast.gif

Per default, date2name gets the modification time of matching files and directories and adds a datestamp in standard ISO 8601+ format YYYY-MM-DD (http://datestamps.org/index.shtml) at the beginning of the file- or directoryname.

If an existing timestamp is found, its style will be converted to the selected ISO datestamp format but the numbers stays the same. Executed with an examplefilename “file” this results e.g. in “2008-12-31_file”.

Note: Other that defined in ISO 8601+ the delimiter between hours, minutes, and seconds is not a colon but a dot. Colons are causing several problems on different file systems and are there fore replaced with the (older) DIN 5008 version with dots.

Usage:
         date2name [options] file ...

Run “date2name –help” for usage hints such as:

Options:
  -h, --help         show the extended help message and exit
  -d, --directories  modify only directory names
  -f, --files        modify only file names
  -S, --short        use short datestamp               (YYMMDD)
  -C, --compact      use compact datestamp             (YYYYMMDD)
  -M, --month        use datestamp with year and month (YYYY-MM)
  -w, --withtime     use datestamp including seconds   (YYYY-MM-DDThh.mm.ss)
  -r, --remove       remove all known datestamps
  -m, --mtime        take modification time for datestamp [default]
  -c, --ctime        take creation time for datestamp
  --delimiter        overwrite default delimiter
  --nocorrections    do not convert existing datestamps to new format
  -q, --quiet        do not output anything but just errors on console
  -v, --verbose      enable verbose mode
  -s, --dryrun       enable dryrun mode: just simulate what would happen, do
                     not modify files or directories
  --version          display version and exit

Installation

First, you need the programming platform Python installed.

Then, you can

  1. get date2name manually from GitHub OR
  2. install it via pip install date2name which is simplest method.

Integration Into Common Tools

Integration into Windows File Explorer

The easiest way to integrate date2name into File Explorer (“Send to” context menu) is by using integratethis.

Execute this in your command line environment:

pip install date2name integratethis
integratethis date2name
integratethis time2name

Manual Integration into Windows Explorer for single files

Use this only if the integratethis method can not be applied:

Create a registry file add_date2name_to_context_menu.reg and edit it to meet the following template. Please make sure to replace the paths (python, USERNAME and date2name.py) accordingly:

Windows Registry Editor Version 5.00

;; for files:

[HKEY_CLASSES_ROOT\*\shell\date2name]
@="date2name (single file)"

[HKEY_CLASSES_ROOT\*\shell\date2name\command]
@="C:\\Python36\\python.exe C:\\Users\\USERNAME\\src\\date2name\\date2name.py -i \"%1\""

Execute the reg-file, confirm the warnings (you are modifying your Windows registry after all) and cheer up when you notice “date2name (single file)” in the context menu of your Windows Explorer.

As the heading and the link name suggests: this method works on single files. So if you select three files and invoke this context menu item, you will get three different filetag-windows to tag one file each.

Integration into Thunar

Thunar is a popular GNU/Linux file browser for the xfce environment.

Unfortunately, it is rather complicated to add custom commands to Thunar. I found a good description which you might want to follow.

To my disappoinment, even this manual confguration is not stable somehow. From time to time, the IDs of $HOME/.config/Thunar/uca.xml and $HOME/.config/Thunar/accels.scm differ.

For people using Org-mode, I automated the updating process (not the initial adding process) to match IDs again:

Script for checking “tag”: do it tag-ID and path in accels.scm match?

#+BEGIN_SRC sh :var myname="tag"
ID=`egrep -A 2 "<name>$myname" $HOME/.config/Thunar/uca.xml | grep unique-id | sed 's#.*<unique-id>##' | sed 's#<.*$##'`
echo "$myname-ID of uca.xml: $ID"
echo "In accels.scm: "`grep -i "$ID" $HOME/.config/Thunar/accels.scm`
#+END_SRC

If they don’t match, following script re-writes accels.scm with the current ID:

#+BEGIN_SRC sh :var myname="tag" :var myshortcut="<Alt>t"
ID=`egrep -A 2 "<name>$myname" $HOME/.config/Thunar/uca.xml | grep unique-id | sed 's#.*<unique-id>##' | sed 's#<.*$##'`
echo "appending $myname-ID of uca.xml to accels.scm: $ID"
mv $HOME/.config/Thunar/accels.scm $HOME/.config/Thunar/accels.scm.OLD
grep -v "\"$myshortcut\"" $HOME/.config/Thunar/accels.scm.OLD > $HOME/.config/Thunar/accels.scm
rm $HOME/.config/Thunar/accels.scm.OLD
echo "(gtk_accel_path \"<Actions>/ThunarActions/uca-action-$ID\" \"$myshortcut\")" >> $HOME/.config/Thunar/accels.scm
#+END_SRC

Integration into FreeCommander

FreeCommander is a orthodox file manager for Windows. You can add date2name as an favorite command:

  • Tools → Favorite tools → Favorite tools edit… (S-C-y)
    • Create new toolbar (if none is present)
    • Icon for “Add new item”
      • Name: date2name
      • Program or folder: <Path to date2name.bar>
    • date2name.bat looks like: (please do modify the paths to meet your requirement)
      C:\Python36\python.exe C:\Users\YOURUSERNAME\src\date2name\date2name %*
      REM optionally: set /p DUMMY=Hit ENTER to continue...
              
      • Start folder: %ActivDir%
      • Parameter: %ActivSel%
      • [X] Enclose each selected item with =”=
      • Hotkey: select next available one such as Ctrl-1 (it gets overwritten below)
    • remember its name such as “Favorite tool 01”
      • OK

So far, we’ve got date2name added as a favorite command which can be accessed via menu or icon toolbar and the selected keyboard shortcut. If you want to assign a different keyboard shortcut than Ctrl-1 like Alt-d you might as well follow following procedure:

  • Tools → Define keyboard shortcuts…
    • Scroll down to the last section “Favorite tools”
    • locate the name such as “Favorite tool 01”
    • Define your shortcut of choice like Alt-d in the right hand side of the window
      • If your shortcut is taken, you’ll get a notification. Don’t overwrite essential shortcuts you’re using.
    • OK

Related tools and workflows

Alternative implementations of date2name:


This tool is part of a tool-set which I use to manage my digital files such as photographs. My work-flows are described in this blog posting you might like to read.

In short:

For tagging, please refer to filetags and its documentation.

See date2name for easily adding ISO time-stamps or date-stamps to files.

For easily naming and tagging files within file browsers that allow integration of external tools, see appendfilename (once more) and filetags.

Moving to the archive folders is done using move2archive.

Having tagged photographs gives you many advantages. For example, I automatically choose my desktop background image according to the current season.

Files containing an ISO time/date-stamp gets indexed by the filename-module of Memacs.

Here is a 45 minute talk I gave at Linuxtage Graz 2018 presenting the idea of and workflows related to appendfilename and other handy tools for file management:

bin/2018-05-06 filetags demo slide for video preview with video button -- screenshots.png

How to Thank Me

I’m glad you like my tools. If you want to support me:

  • Send old-fashioned postcard per snailmail - I love personal feedback!
  • Send feature wishes or improvements as an issue on GitHub
  • Create issues on GitHub for bugs
  • Contribute merge requests for bug fixes
  • Check out my other cool projects on GitHub

date2name's People

Contributors

jdcorless avatar nbehrnd avatar novoid avatar rrottmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

date2name's Issues

note error retracting time stamp --withtime

date2name fails to revoke successfully the time stamp --withtime date2name prepends.

The version hosted on PyPi (May 9, 2018) does not understand (yet) --remove altogether when presenting a file in pattern of 2021-09-22_test.txt. The current version hosted on GitHub (commit 051254b, Sep 20, 2021) recognizes --remove but truncates 2021-09-21T13.59.59_test.txt only to 21T13.59.59_test.txt; the anticipated pattern would be test.txt.

For documentation, the attached .zip contains test_generator.org from which Makefile and testing test_date2name.py are tangled. To ease visual comparison in a file browser like Thunar while performing the tests, additional delays are set; this form of the .org thus is /not/ for inclusion in the in the project's Git history.

2021-09-22_date2name.zip

--ctime uses current date on macOS

Here's an example of me trying to add the date to a standard text file:

$ stat -f "%SB" pipeline.sh
Oct 19 20:51:22 2018

$ date2name --ctime pipeline.sh
/pipeline.sh                              →  2019-04-01_pipeline.sh

It looks like date2name can't read the "birth time" correctly on macOS, as it's just prepending today's date to the file.

It does pick up the mtime

$ mv 2019-04-01_pipeline.sh pipeline.sh

$ date2name --mtime pipeline.sh
/pipeline.sh                              →  2018-10-19_pipeline.sh

…but this isn't great, as I want to rename lots of old files that I've modified after the creation date.

I did a little digging, and it looks like you can call os.stat(path).st_birthtime here to get the real created time. I'm not sure whether there's any cross-platform compatibility to worry about with st_birthtime though.

Thanks for the nice tool 😃.

update on pypi, README.org is not well supported

The project description of date2name (2024.3.10.1) on pypi doesn't resolve well.

The documentation page appears like a copy-paste of the README.org; however contrasting to for instance GitHub, pypi doesn't appear to support the orgmode syntax (yet). Maybe the a C-e h h to generate an .html were an approach more suitable here.

2024-03-11_date2name_pypi_01-800

2024-03-11_date2name_pypi_02-800

I got to know about the update because it is one of the pages update scanner checks this once a day for me.

-c [creation date] using current date

I am using date2name -c file.txt and getting the current date prepended (2020-06-10), instead of the creation date. The file's creation date is 2013-08-13, and its modification date is 2020-06-08. I wonder whether I am doing something wrong (!). Thanks for any tips.

Installation

Could you provide instructions on the installation process?

Rename based on EXIF creation date

Excellent tool! I was wondering if you are planning on extending the rename functionality based on EXIF creation date (useful for media files).

Extract EXIF time-stamp from JPEG image header

Add the ability to extract the EXIF data from images, and use that for the filename date on image files.

I noticed you use a bash script for your camera files, but it could be useful to have included in this script.

Write unit tests

This beautiful tool deserves a set of basic unit tests, testing the main functionality.
I don't have the expertise to define proper tests that check the correct handling of different timestamps. If you do think you do have a nice idea how this could be done, please drop me a line or a pull request.

Feature Request: Inherent Tags

Hello Novoid! I began using FileTags recently to replace an older sorting system I've been using for years. One of my favorite features in FileTags is the ability to use mutually exclusive tagging, which has made my life a whole lot easier.

That being said, I find myself seeking more efficiency in my workflow. I think an excellent way to achieve this would be through Inherent Tags, which would allow a single tag to imply other tags.

For example, suppose I wanted to tag a photograph with "dogs"; it could then be assumed that I also wanted to tag the photo with "animals". Another example would be "bacon", which could have the inherent tag "food". This would be an excellent way to apply multiple tags in half the effort, which is something important for my personal workflow.

I wouldn't claim to know how this could be implemented into your model, but I imagine it integrated in a similar way to how mutually exclusive tags currently exist. Perhaps inherent tags would be contained within brackets {dogs animals} or derive their meaning through a precursor (+dogs +animals) in the same line.

Naturally this only shaves off a few moments, but in the grand scheme it speeds things up considerably over long sessions. I'm curious to hear your thoughts either way, thanks for the tools!

pip install does no longer install the script

Previously pipx install date2name or pip install --user date2name installed the script for the user (in Linux) under ~/.local/bin. Seems the upgrade to poetry broke this since no script is installed anymore. For example pipx gives the following error indicating that no script or binary is installed:

No apps associated with package date2name or its dependencies. If you are attempting to install a library, pipx should not be used. Consider using pip or a similar tool instead.

Changing the the scripts section to use poetry solves this for me when installed locally:

-[project.scripts]
+[tool.poetry.scripts]
 date2name="date2name:main"

underscore after date sometimes appears and others not

file.txt becomes 2018-11-3_file.txt

whereas

file1518722398544 - Copy somename.jpeg ---> 2018-03-11 file1518722398544 - Copy somename.jpeg

with no underscore.

So, I was wondering, is this a feature? At what times should we expect the _ (underscore) to appear after the file name. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.