Reinventing file storage with semantic tagging

Date2name and Appendfilename

The Date2name tool [7] adds the date and timestamps at the beginning of the file name. The command:

date2name "foo bar.txt"

renames the file to 2019-09-26 foo bar.txt.

date2name --withtime "foo bar.txt"

would give you 2019-09-26T14.45 foo bar.txt.

One frequently recurring step when working with files is adding words from the actual file name. If you want to add a description to a photo named 2019-09-26T14.52.36.jpg, use the Appendfilename [8] tool. The following call:

appendfilename --text="foo bar" 2019-09-26T14.52.36.jpg

renames the file to 2019-09-26T14.52.36 foo bar.jpg. Without the --text parameter, the tool waits for text input in interactive mode.

If you wrap the call in a script, as shown in Listing 2, Appendfilename can extend all selected files in a file browser after you enter and confirm the text in the window that appears.

Listing 2

Wrapping Appendfilename

/usr/bin/gnome-terminal \
  --geometry=90x5+330+5 \
  --hide-menubar \
  -x appendfilename "${@}"

Filetags

Like Appendfilename, Filetags [9] adds text to the file name, but without you needing to worry about separators in front of the tags. Both the command in the first line of Listing 3, and the one in the second line result in foo -- bar baz.txt as the file name. The command form in Line 3 converts back to foo.txt.

Listing 3

Adding Tags

$ filetags --text "bar baz" "foo.txt"
$ filetags --text "baz" "foo -- bar.txt"
$ filetags --remove --text "baz bar" "foo -- bar baz.txt"

In interactive mode without the --text parameter, you can remove existing tags by prepending a minus sign: -bar baz removes the bar tag and adds baz.

The tool also suggests tags based on their use in other files in the same directory. These suggestions assign file tags with numbers starting at 1. You can reuse these abbreviations in your input. For example, interactively inputting 1 bar 42 tells the tool to add suggestions 1, 2, and 4 together with the bar tag.

In addition, Filetags offers a tab completion option. To manage this, it is a good idea to create a .filetags file in the current directory or a parent directory. The software searches recursively upwards; the first definition file found wins. This means you can have different definitions for different hierarchies.

The structure of this text file is very simple. Each line consists of one or more tags. If several of them are in one line, Filetags treat them as mutually exclusive. Based on the .filetags file in Listing 4, if you add a tag of foo -- draft.txt to a final file, Filetags will automatically replace the draft tag with final instead of appending it.

Listing 4

.filetags File

presentations
cheatsheets
cliparts
finance
manuals
templates
draft final submitted

Guessing and Unpacking

The Guessfilename [10] tool, written in Python, helps to rename frequently used file names. Using pattern recognition in the file name and by parsing the contents where necessary, it determines variants for the file names. If your monthly pay slip is sent in the form of a PDF file such as Salary.pdf, it recognizes the Salary character string and the PDF file type by reference to a configured pattern and generates the new file name 2019-09-29 Pay slip September -- finance company.pdf.

It is in the nature of things that you have to adapt Guessfilename to suit your own needs – it is practically just a template for customization. To customize the crucial derive_new_filename_from_old_filename() function, you need basic Python programming skills.

To compensate for the overhead, you can look forward to many simplifications in daily file handling. I use Guessfilename not only for pay slips, but also for audio recordings, digital photos directly from the camera, screenshots, invoices, and other files – wherever programs do not let you configure the file name to suit a desired scheme.

The Guess-target-folder.sh and Move2archive [11] tools take care of the next logical step: moving the files to the appropriate target folder. Both scripts in this form are usually only useful on Unix-style operating systems.

Guess-target-folder.sh is a trivial, but again highly personalized, shell script. Listing 5 outlines the basic mechanism. Move2archive behaves in a very similar way, but it does not support pattern recognition. It simply moves the files to a folder structure, where the directory names consist of an archivepath (like $HOME/archive/) and the year.

Listing 5

Guess-target-folder.sh

# Guess-target-folder.sh
#
file="${1}"
move_file()
{
  file="${1}"
  targetdir="${2}"
  echo "* ${file}\n  ->  ${targetdir}"
  mv "${file}" "${targetdir}"
}
case "${file}" in
  20*Columbo*mp4)
    move_file "${file}" "$HOME/tv/detectivestories/";;
  20*Meter_reading\ Water*pdf)
    move_file "${file}" "$HOME/correspondence/wasser/";;
  *Salary*pdf)
    move_file "${file}" "$HOME/correspondence/company/";;
  *1234567*|*1.234.567*)
    move_file "${file}" "$HOME/correspondence/insurance/";;
esac

The two Python scripts can be installed using Pip3 if required. The particularly annoying integration on Windows systems prompted the development of Integratethis [12], which supports easy integration into Windows Explorer. But there is no reason why it should not be taught how to integrate with Geeqie, Thunar and other interfaces. Appropriate pull requests on Github are welcome.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus