Good evening,
Is there a way (or a tip) to sort files in the list view based on the length of the filename? The idea is, after that, to be able to organise different types of batch renaming, depending of the length of the filenames.
Of course, I can do it externaly with an other tool.
But links are broken with the categories, as the database is not anymore synchronised with the new names of the externaly renamed files.
Best.
Sorting files depending the length of the filename
Moderator: xnview
-
SD45
- Posts: 10
- Joined: Mon Jan 01, 2018 9:40 am
-
jkm
- Posts: 579
- Joined: Sat May 11, 2024 12:43 am
Re: Sorting files depending the length of the filename
This is an interesting (although strange) question, so I'll try and point out some ways you can go.
There's no built in way to sort by the length of the filename, but I can think of a couple of ways out of your predicament.
(Why you would have this requirement is opaque to me, but I'll assume you have some reasonable and immutable reason, that can't be addressed any other way.
I will point out that if you're using ARen for your renaming, then right in that app, you can pre-filter based on the length of the filename (and take conditional actions if necessary), obviating the need to do it in XnViewMP)
First, your "broken categories" issue, which is the easier to address. This is only a problem if you're not taking proper care of your metadata. If you embed the categories in the image files (or in sidecar files, which get renamed with the master files), then when you re-import the files (which will seem to be new files from XnViewMP's perspective) the categories will already be there, so there is no problem. This is done with a few clicks, and in my view would be the best way to deal with this situation.
If you refuse to do that, then it is possible to sort by the length of the file name in XnViewMP, but you will have to put some work in.
This can be achieved using an Exiftool column in details view. There are two approaches...
The first involves a bit of customization to Exiftool. You will need to create (in your .Exiftool_config file) a custom user-defined tag that returns the length of the file name. This would be easy to do, if you have any programming experience. User-defined tags in Exiftool are simply Perl code, and can return any arbitrary information you like. Simply return the length of the file name, with or without extension, as you prefer. Once this is done, simply Update Metadata (in Settings:Catalog) for your files, and the new column will be available, and you can sort by it.
The second approach is for if you're afraid of Perl (which would be understandable). Exiftool (from the command line) can set (almost) any defined tag to a new value. Simply write a batch script that computes the length of the filename, stores it in an environment variable, and then executes Exiftool against the file to set a pre-defined tag of your choosing to the value of the environment variable. Then afterwards, as before, Update Metadata and you add that tag as an Exiftool column in the app, and sort by it.
If you feel either of the Exiftool approaches are beyond you, then an AI chatbot might be able to help with the script, or someone on the Exiftool forums might be willing to help you with the user-defined function.
Hopefully this helps...
Good luck.
There's no built in way to sort by the length of the filename, but I can think of a couple of ways out of your predicament.
(Why you would have this requirement is opaque to me, but I'll assume you have some reasonable and immutable reason, that can't be addressed any other way.
First, your "broken categories" issue, which is the easier to address. This is only a problem if you're not taking proper care of your metadata. If you embed the categories in the image files (or in sidecar files, which get renamed with the master files), then when you re-import the files (which will seem to be new files from XnViewMP's perspective) the categories will already be there, so there is no problem. This is done with a few clicks, and in my view would be the best way to deal with this situation.
If you refuse to do that, then it is possible to sort by the length of the file name in XnViewMP, but you will have to put some work in.
This can be achieved using an Exiftool column in details view. There are two approaches...
The first involves a bit of customization to Exiftool. You will need to create (in your .Exiftool_config file) a custom user-defined tag that returns the length of the file name. This would be easy to do, if you have any programming experience. User-defined tags in Exiftool are simply Perl code, and can return any arbitrary information you like. Simply return the length of the file name, with or without extension, as you prefer. Once this is done, simply Update Metadata (in Settings:Catalog) for your files, and the new column will be available, and you can sort by it.
The second approach is for if you're afraid of Perl (which would be understandable). Exiftool (from the command line) can set (almost) any defined tag to a new value. Simply write a batch script that computes the length of the filename, stores it in an environment variable, and then executes Exiftool against the file to set a pre-defined tag of your choosing to the value of the environment variable. Then afterwards, as before, Update Metadata and you add that tag as an Exiftool column in the app, and sort by it.
If you feel either of the Exiftool approaches are beyond you, then an AI chatbot might be able to help with the script, or someone on the Exiftool forums might be willing to help you with the user-defined function.
Hopefully this helps...
Good luck.