Command: Find and Replace Metadata

:warning: This script add-in is deprecated. Use DO Meta Wizard Command instead.

Find and Replace Metadata is a Directory Opus script command that simplifies the task of editing metadata allowing you to modify them by specifying the content to find and their replacement in the selected metadata properties.

Its main features are:

  • Support for almost all metadata properties editable by Directory Opus.
  • Easy selection of metadata properties to edit, with search support.
  • Support for deleting metadata properties based on search criteria.
  • Support for regular expressions, ignoring diacritics, whole words and match case.
  • Extended file information can be used in the Replace field, with support for most DOpus metadata insertion codes (e.g. {file}, {mp3artist}, etc.), similar to Advanced Replace dialog.
  • Preview of changes to be made for each file (in the Files tab).
  • Easy to use, fully multilingual UI (in all languages supported by DOpus).
  • Automatic creation of logs, so that you can track the changes made by the command and even undo them.

:warning: IMPORTANT: READ BEFORE PROCEED

This script is provided "as is" and without warranty of any kind.
It has been made during my spare time and has not been extensively tested, so it is presented as a testing version and should be used with extreme caution.
The user assumes full responsibility for its use and understands that the author is not responsible for possible failures or loss of data.
It is strongly recommended that files be backed up before using them with this script.
Any feedback on possible improvements or bugs is welcome.

BEFORE YOU BEGIN

  • Re-read the notice above.
  • Read all the info about SETATTR information on this page. It is important that you know what kind of values (text, numeric, etc.) each property uses before you start playing with this command.

HOW TO INSTALL
Download the file below. Then run Prefs SCRIPTINSTALL and select the downloaded file.
:warning: IMPORTANT: Needs at least v13.0.54
v1.0.7: Find and Replace Metadata.opusscriptinstall (15.3 KB)

OPTIONS
In the Script Management window, select Find and Replace Metadata and click in Edit button.

  • after_actions: Choose among several options to be performed after the command has been completed.
  • debug: Useful if you have some problems with results obtained and want to see the command line generated by the script. You can select the log level as OFF, ALL or WARNING.
  • doc_exts: File extensions that will be considered as "true" documents (e.g. can have Author, Subject, etc).
  • logs_path: Folder path where log files will be stored.

USAGE
You can use Find and Replace Metadata with the selected files in the source Lister, by simply invoking it with FRMeta.

Other arguments are:

COMMAND ARGUMENTS

ARGUMENT TYPE DESCRIPTION
CASE /S Start the dialogue window with 'Match Case' checked
FILES /K/M Specifies the name of the file or files to use with this command. If you don't provide this argument the command operates on all selected items in the source Lister.
FIND /K Set Find edit control content when starting the dialog window
NODIACRITICS /S Start the dialogue window with 'Ignore diacritics' checked
NOEMPTY /S Disables edition for those metadata properties that are originally empty
NOGLOBAL /S Find and replace only applies to the first match. (disables 'g' flag in pattern)
NOMULTILINE /S Disables multiline mode match (disables 'm' flag in pattern)
OPENINFILES /S Lets you open the dialog with the Files tab active
PROPERTIES /K Set metadata properties to edit when starting the dialog window
REGEX /S Start the dialogue window with 'Regular expressions' checked
REPLACE /K Set Replace edit control content when starting the dialog window
WHOLEWORDS /S Start the dialogue window with 'Whole words' checked

The script will generate 2 files in the folder of your choice (or in /profile\DOpus_F&RLogs) if any metadata changes are made. The "Files" file contains the SETATTR commands run by the command.
The "Backup" file contains the SETATTR commands needed to undo the changes made (that is, using the original values). You can copy these commands (e.g. to a button) and run them if you wish.

NOTES / FURTHER DEVELOPMENT

  • Your feedback is important for possible improvements and bug fixes.

  • Please refrain from using it on 300,000 files at once for the time being.

  • If the replace value for a meta property is empty (''"), after expansion, that property won't be changed. In order to delete a property, use the {empty} keyword in the Replace edit control. e.g. If you want to delete a property regardless of their content:

    • Select the desired properties you want to delete from the list.
    • Use in Find edit control : .*
    • Use in Replace edit control : {empty}
    • :ballot_box_with_check: Check Regular Expressions
  • Yes, with this tool you can also set the value of a property based on other metadata values. e.g. set the comment as a combination of artist, album and title values.

  • Yes, it is deliberately not being able to set creation, modification and access dates. I think DOpus already has many ways to do that. But you can use those values (as extended information) in other supported properties.

  • It is in my plans to support the same pattern matching syntax used by Directory Opus (this one) when regular expressions is unchecked, although I haven't had enough time to do it myself. I think that there is no quick way to do it, the ideal would be to use Wild object and that this has a way to return an equivalent pattern that can be used with RegExp, or that there exists a method to make replacements using the pattern returned by Wild (e.g. Wild.replace(pattern,replace)).

  • I didn't set hotkeys. I forgot, sorry. But you can give ideas on which ones to add.

KNOWN ISSUES

  • The command does not perform any check on the data types to be written and their compatibility with the property you intend to write to, so again, use it carefully.
  • The submenus when inserting extended information sometimes appear far away from the Replace edit control, this is expected. AFAIK you cannot create actual submenus and they are always displayed at the current mouse coordinates.
  • The fact that the find and replacement pattern are multiline is to make it easier to enter and read the data, it does not mean that the values entered will be multiline (line breaks are replaced by a space).
  • Some files are recognised as Documents, even if they have only 1 or 2 general values of this type. And if you try to write a property not allowed in these files, DO will show an error. To avoid that, use doc_exts in configuration to define all the extensions you want to consider as "true" documents. If a file recognized as document doesn't have their extension registered in there, ONLY those properties already existing can be edited (like an NOEMPTY implicit for those files).
  • In the Files tab, at the top of the property list of the selected file, its full path and its filetype group are displayed. When the path is too long and does not fit on one line, the full information is not displayed. Solved by resizing the dialog a bit (seems to be a problem with self-sizing controls).
  • Some properties cannot be edited with this command, because they require a value that has a specific meaning. I will consider adding support for these properties in the future if there is a request.
List of unsupported properties
  • Contrast
  • Exposure program
  • Flash
  • Metering mode
  • Rotation
  • Saturation
  • Scene capture type
  • Sharpness
  • White balance
  • Compilation
  • Cover art

CHANGELOG
v1.0.7 (2024-01-18)

  • Added doc_exts in script configuration to define file extensions that are going to be considered as "true" documents (e.g. can have Author, Subject, etc).
Complete changelog

v1.0.6 (2023-12-26)

  • Improved search functionality for metadata preview in Files Tab. You can now configure search options from the same dialog (match case, regular expressions, ignore diacritics and whole words are supported).
  • Minor changes in UI.

v1.0.5 (2023-12-21)

  • Several changes in UI. You can give feedback if you like/dislike those changes.
  • Added new arguments: PROPERTIES, CASE, NODIACRITICS, REGEX, WHOLEWORDS, REPLACE and FIND, which allow to pre-fill the dialogue window.
  • You can now change the value of Global and Multiline replacement on runtime.
  • Properties can now be removed, using the keyword {empty} in the Replace edit control.
  • Added some missing editable properties.
  • Added a fix for files recognised as Documents, which were showing an error when trying to write a property they cannot have (read KNOWN ISSUES above).

v1.0.4 (2023-12-20)

  • Fixed an issue with the progress window not hiding.
  • Fixed some extended keywords being messed up.
  • Now the new values are calculated only when needed.

v1.0.3 (2023-12-19)

  • OPENINFILES argument lets you open the dialog with the 'Files' tab active.
  • Now is possible to check/uncheck files, to decide on runtime on which files the changes will apply.
  • Small changes/fixes in UI.
  • Changed properties in Files tab now are more visibles.
  • Code cleanup and overall script file reduction.

v1.0.2 (2023-12-18)

  • Minor update to get in line with some fixes in v13.0.53.

v1.0.1 (2023-12-17)

  • Revamped UI, now you can see all keyword values available for each file.

v1.0.0 (2023-12-10) : Initial release

6 Likes

Thank you! I am eager to check this out! I have requested this before. I am a professional photo organizer, and Photo Mechanic (by Camera bits) has an excellent Find & Replace feature for all photo metadata fields (maybe not all - but all the fields I care about).

v1.0.1 brings some minor changes in UI, so for the few people who find this command useful, any feedback is welcome.

1 Like

v1.0.2 needs DO v.13.0.53 or later. Now can load/save the dialog position using official methods.

4 Likes

Hi, very good script.

It bugged out once so far. Printed a 1120 bpm instead of 120.
Also could you make it log the changes in the background instead of the notepad pop up please.

Thanks for asking @ASUNDER

Unlikely, since the command only does the replacement. If you can look in the logs for the initial and final value it would help a lot. My bet is that the initial value was 160 and your replacement options were "60" for "120". If you only want to replace when the whole value is 60, you can try checking "whole words" (or use regular expressions for something more advanced). You can always preview the change in the Files tab.

It's already there. You can change after_actions to "Nothing" in script management options. (You can use Prefs SCRIPTS="Find and Replace Metadata.js*" for that). I think I forgot to mention or make a better explanation in the main post, more out of laziness since I thought no one was going to use the command :smile:

2 Likes

If you have time, could you add a switch to choose which tab is initially opened - either Find and Replace or Files? I enjoy following your exploration of the many less traveled corners of DO13. TIA

@jinsight Could you elaborate a little more on why you want to start on the Files tab sometimes?
Because it seem to me that since the main idea is to search and replace on the selected metadata, wouldn't it be confusing to start in another section?

Yup it did find a 160 bpm and changed it to 1120. I think 'whole words' enabled is what fixes that issue.
Changing the 'after action' setting to 'nothing' worked, thank you.
Being able to change the log folder location is good too.
Awesome script.

1 Like

Before doing a find and replace, I want to see the current metadata. Thanks for the NOEMPTY switch. With it, I can go to the Files tab and see just the fields with data. It isn't a high priority item for me. After all, it's one extra click. Thanks for responding.

1 Like

In v1.0.3 you will be able to open the dialog with the Files tab active adding OPENINFILES as an argument.
There are also some changes/fixes, so let me know if there's something broken, since I change several parts in the code.

1 Like

Thank you so much!

sorry, now it doesn't work on non images files and video (like .js or .dxf), just hangs even on 1 file so i need to exit DO (no abort button works, v13.0.54)
image

Thanks @fkast. By any chance you just use the command in very few files with little to no metadata?
Because I can reproduce the issue that way. Seems more related to something in the progress window. When is called and it is hidden very quickly, it is as if Hide() has no effect, besides taking the focus and minimizing the command window. Very strange...
I have made some changes to make the progress window last a little longer visible(?), plus it is no longer linked to the Lister. Can you download the script again from the main post and let me know if it works please.

yes, now works

Good. You can update now to v1.0.4, that also fixes other problems.

I have a lot of files with different attributes for the same metadata, while I'm not sure exactly what all. Is it possible to implement the following two functions:

  1. clear all the specified metadata attributes.
  2. Skip the lookup and write the replacement directly into the metadata attribute value.

@JCDARK :

  1. In the next update. you'll be able to delete a metadata property using {empty} as a keyword.
    e.g. If you want to delete a property regardless of their content:
    • Select the desired properties you want to delete from the list.
    • Use in Find field: .*
    • Use in Replace field: {empty}
    • Check Regular Expressions :ballot_box_with_check:
  2. No, sorry, that's not the aim of this command. If you want to automate metadata edition have a look at SetAttr command.
1 Like

v1.0.5 is out and it brings quite a few changes! Read the main post to find out about them :wink:

1 Like

extremely grateful

1 Like