novoid / appendfilename Goto Github PK
View Code? Open in Web Editor NEWIntelligent appending text to file names, considering file extensions and file tags
License: GNU General Public License v3.0
Intelligent appending text to file names, considering file extensions and file tags
License: GNU General Public License v3.0
There are certain situations where I need to remove one or more words from selected file names.
One example is after added a set of words that contain a typo.
An implementation of this would also addresses #8
This issue is a central spot to collect ideas on how to come up with a consistent concept to remove words. This has to work on one file as well as on a group of selected files. It has to work on file names that end with the same set of words as well as with sets of files that do have completely different file names.
Furthermore, there should be ways to deal with edge cases. A few examples:
-2
which results in removing the last two words (separated by spaces or underscores) from the file name.filetags
, the user might be able to interactively enter -"foo bar"
or -foo
to remove the words "foo bar" or "foo" from the end of the existing file names of selected files. If not found, nothing gets removed. Filetags are ignored and are not considered being part of the file name here.Please add your ideas here as well!
The option --smart-prepend
aims to keep time stamps (added by date2name) in front of the file name. However, for stamps assigned with either --compact
, --month
, or --short
, the pattern generated differs; here, the text is leading ahead of the time stamp.
For example, in a live session of Xubuntu 20.04.2 LTS/Fossa and a pristine checkout of appendfilename/master, these are the observations:
xubuntu@xubuntu:~/Desktop/appendfilename/appendfilename$ python3 __init__.py 20211231_test.txt --smart-prepend --verbose -t book
DEBUG 2022-01-09 13:01:24,885 text found: [book]
DEBUG 2022-01-09 13:01:24,885 extracting list of files ...
DEBUG 2022-01-09 13:01:24,885 len(args) [1]
DEBUG 2022-01-09 13:01:24,885 1 filenames found: [20211231_test.txt]
DEBUG 2022-01-09 13:01:24,885 iterate over files ...
DEBUG 2022-01-09 13:01:24,885 options.smartprepend is set with ||book| |20211231_test|.txt
DEBUG 2022-01-09 13:01:24,885 options.smartprepend is set with |<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>
DEBUG 2022-01-09 13:01:24,885 can't find a date/time-stamp, doing a simple prepend
DEBUG 2022-01-09 13:01:24,885 renaming "20211231_test.txt"
DEBUG 2022-01-09 13:01:24,886 ⤷ "book 20211231_test.txt"
DEBUG 2022-01-09 13:01:24,886 successfully finished.
Please press <Enter> for finishing...
xubuntu@xubuntu:~/Desktop/appendfilename/appendfilename$ python3 __init__.py 2021-12_test.txt --smart-prepend --verbose -t book
DEBUG 2022-01-09 13:04:26,884 text found: [book]
DEBUG 2022-01-09 13:04:26,884 extracting list of files ...
DEBUG 2022-01-09 13:04:26,884 len(args) [1]
DEBUG 2022-01-09 13:04:26,884 1 filenames found: [2021-12_test.txt]
DEBUG 2022-01-09 13:04:26,884 iterate over files ...
DEBUG 2022-01-09 13:04:26,884 options.smartprepend is set with ||book| |2021-12_test|.txt
DEBUG 2022-01-09 13:04:26,884 options.smartprepend is set with |<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>
DEBUG 2022-01-09 13:04:26,884 can't find a date/time-stamp, doing a simple prepend
DEBUG 2022-01-09 13:04:26,884 renaming "2021-12_test.txt"
DEBUG 2022-01-09 13:04:26,885 ⤷ "book 2021-12_test.txt"
DEBUG 2022-01-09 13:04:26,885 successfully finished.
Please press <Enter> for finishing...
xubuntu@xubuntu:~/Desktop/appendfilename/appendfilename$ python3 __init__.py 211231_test.txt --smart-prepend --verbose -t book
DEBUG 2022-01-09 13:05:26,694 text found: [book]
DEBUG 2022-01-09 13:05:26,694 extracting list of files ...
DEBUG 2022-01-09 13:05:26,695 len(args) [1]
DEBUG 2022-01-09 13:05:26,695 1 filenames found: [211231_test.txt]
DEBUG 2022-01-09 13:05:26,695 iterate over files ...
DEBUG 2022-01-09 13:05:26,695 options.smartprepend is set with ||book| |211231_test|.txt
DEBUG 2022-01-09 13:05:26,695 options.smartprepend is set with |<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>
DEBUG 2022-01-09 13:05:26,695 can't find a date/time-stamp, doing a simple prepend
DEBUG 2022-01-09 13:05:26,695 renaming "211231_test.txt"
DEBUG 2022-01-09 13:05:26,695 ⤷ "book 211231_test.txt"
DEBUG 2022-01-09 13:05:26,695 successfully finished.
Please press <Enter> for finishing...
These observations are coherent with the automatic testing with the test script for pytest for Python 3 just extended, e.g., by
pytest-3 test_appendfilename.py -m "smart" -v
Suggestion.
The code has some constants Iike separators and ignored words that are hardcoded. Since I used pip to install, it is hard to customize this. My suggestion would be to move these constants to a hidden config file in $HOME
, like $HOME/.appendfilename
or $HOME/.config/appendfilename
.
https://unix.stackexchange.com/questions/68721/where-should-user-configuration-files-go
In linux not having any spaces in file names can have lots of advantages, so is there any way appendfilename uses _ between words instead of spaces? Thanks in advance.
appendfilename
functions differently for files stamped by date2name
in either default, or --withtime
time stamp.
Manual replication:
touch ping.txt
date2name ping.txt
appendfilename 2022-01-06_ping.txt -t new --smart-prepend
to yield
ERROR Error while trying to build new filename: <class 'TypeError'>
ERROR 1 error(s) occurred. Please check output above.
An analogue programmatic replication with the test script approach (just submitted, incomplete coverage, under construction) with pytest
/pytest-3
for Python3:
pytest-3 test_appendfilename.py -m "smart" -v
File 2021-12-31T18.48.22_test.txt
is processed as 2021-12-31T18.48.22 book test.txt
and thus successfully removed by the test script. However, test file 2021-12-31.txt
is processed to 2021-12-31 book txt
loosing the period en face of the file extension. (File test.txt
is processed by appendfilename to book test.txt
, thus indicating appendfilename works fine on this one.).
So which command can we use for removing previously added file name additions? Thanks in advance.
This does not work here.
-x /home/mj/snippy/geeqie/appendfilename/appendfilename/__init__.py --remove "${@}"
OS: Windows 10
Installed via: pip
I am happy to provide more information if needed.
Calling appendfilename
with --smart-prepend
option works as expected when given relative path:
appendfilename --smart-prepend relative/path/to/"2023-02-14 file.txt"
... with interactive input of "beginning" results in:
"2023-02-14 beginning file.txt"
However, calling it with an absolute path ignores the timestamp and acts like normal --prepend
option:
appendfilename --smart-prepend absolute/path/to/"2023-02-14 file.txt"
... with interactive input of "beginning" results in:
"beginning 2023-02-14 file.txt"
Not sure why. Maybe you have some useful hints?
Thanks for sharing. Cool youtube video.
appendfilename should rename all linked "parent links" as long as the file name is the same. However, this seems to work only for the first link and not for all.
files/*
to tagtrees1/
and then from tagtrees1/tag/*
to tagtrees2/
(all within the same parent directory)tagtrees2/tag/foo -- tag.txt
that points to tagtrees1/tag/foo -- tag.txt
which points to files/foo -- tag.txt
appendfilename -t "foobar"
results in:tagtrees2/tag/foo foobar -- tag.txt
tagtrees1/tag/foo foobar -- tag.txt
files/foo -- tag.txt
<-- here, the renaming/recursion stops which is wrong. It should be: files/foo foobar -- tag.txt
Adapt def handle_file_and_symlink_source_if_found(filename, text, dryrun)
so that it works recursively just like filetags
does with tags.
When working with tag filter view or Tagtrees view of filetag
, shortcuts are created whose file names correspond to the original file (but directory differs).
appendfilename
is supposed to add additional text to the shortcut file as well as the original file (as long as their file names are same). This does not work with Windows 10.
I am trying some of your tools and found a need to prepend some text to the filename. That is, between the date/timestamp and the original filename.
For example the command
appendfilename --prepend --text="Invoice" *.pdf
would change the name of
2018-11-16 Apple 123456.pdf
to
2018-11-16 Invoice Apple 123456.pdf
I had to take a look at the code in this repo to find the available command line switches.
It would be nice if a --help
and/org -h
switch would show the syntax. Or, the syntax could be shown if no arguments are passed at all (instead of the current error message).
Hello Karl,
I learned about your tools by watching your presentation at the Frazer Linuxtage and tried them out afterwards.
I think your tools are absolutely great and I can use them to improve my workflow. I'm using Thunar as a file manager and I integrated your tools through the GUI Edit / Custom Actions, so that I have them in the right click menu. There was no problem with that at all and I think it is easier than editing the config of Thunar the way you are mentioning it in the readme. The only thing that is a little bit strange on my desktop is the position of the window that is opening in interactive mode. But this is an issue that comes because of my windows manager (i3) and is not related to thunar or your tools.
HAGO
Bjoern
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.