Need a script event or work around for "OnDirectoryNameChanged"

Hello dear support team,

I just learned about scripting. I need to write an extension, where an additional action is taken, whenever a directory name (or file name) was changed. Ideally such events should provide data containing the the old- and new name.
Unfortunately, I could not find such an event and the events OnAfterFolderChange or OnBeforeFolderChange doesn't really help, because none of them are triggered if there's only a name change on folders.
My question: How can I achieve my task? Is there a work around that helps me doing this? Are such events planned for the future?

Thank you very much for your help.
Best regards,

Do you mean even when something else renames the folder? Or when you rename it with Opus?

Hi Leo,
No, I mean, when I rename a folder or a file using Dopus. This is sufficient for my usecase

You could do it through a rename script (or a general script, for that matter), but you'd have to ensure you did the rename using that method and not another.

What do you need to do in more detail?

Hi Leo,
Basically, when a rename was done, we need to be informed about that, including old name and new name and then calling an external program to do kind of reindexing.

You would have to ensure you always renamed the folder in a specific way (e.g. using a particular button/hotkey).

You could modify something like the standard F2 hotkey (or whatever you typically use to rename things) to do this, while keeping normal behavior when renaming things that aren't the special folder. But you may find it hard to modify every single possible way the folder could be renamed to ensure it triggers the extra actions you need, since there are so many ways to rename something (both inside and outside of Opus). e.g. You might change F2 but then rename the folder using the Rename button on the toolbar, or right-click > rename in the context menus. You can modify those as well, but there still are other ways the rename could be done, etc.

Another approach would be to have a special button or hotkey just for renaming the special folder. That could ask you for the new name, then rename the folder, and finally run your additional actions and pass them the old and new names. That would be the most simple way to do things, but you'd have to remember to use that special button.

The best approach depend on how automatic you want it.

If you want it to be really automatic, and handle renames that are done outside of Opus, then having something which monitors the filesystem for changes might make sense. There are tools for doing that, but they also have some downsides, since filesystem monitoring isn't always 100% reliable.

Let me know which approach you think makes most sense for you and I can give more detailed advice on how to achieve it.

Hi Leo,

Thank you for the detailed answer,
I already considered such a situation but i guess, the users wouldn't be happy with it, because usually, they just click twice on a folder- or filename to switch to the renaming mode and afterwards they change the name.

Monitoring the filesystem is no option to go, because the filesystem is huge with many thousands of folders and files.

Because there is no "OnRenameFolder" event, my second idea was to check the folder name programmatically for a change whenever the folder name was clicked (not double clicked, as this would open the folder), But for this I would need to be informed of such a click. I couldn't find any reasonable event that could be used to achieve this. Is there an event i could use?

Best regards,

There aren't events (in Opus) to track every rename or click, unfortunately.

With a monitoring tool (or using the Win32 API) you should be able to monitor just the parent folder of the one you want to keep an eye on, and set the monitoring to be non-recursive. That should reduce the amount of extra notifications you would have to skip.

In the next update we'll add a script event that will let you get notified when Opus renames a file. (It won't notify you of renames that happen externally however.)

Thank you, Leo. I'll have a look on that

Hello Jon,
Sounds good :+1:. Was it already planned or will you implement it because of my suggestions?
In what exact version number will it be included?
Thanks a lot for this information.
Best regards,

Your suggestion was the trigger but I remember it's been requested before. Doesn't look like it'll actually be that hard to add so it should make the next beta (12.10.3).

The beta version is out now.

Here's an example script that uses the new event. It will print out (to the script output window - Help / Logs / Script Log) information about rename commands.

option explicit

' fileoptest
' (c) 2018 jpotter

' This is a script for Directory Opus.
' See for development information.

' Called by Directory Opus to initialize the script
Function OnInit(initData) = "fileoptest"
	initData.version = "1.0"
	initData.copyright = "(c) 2018 jpotter"
'	initData.url = ""
	initData.desc = ""
	initData.default_enable = true
	initData.min_version = "12.0"
End Function

' Called to provide notification that a file operation is complete
Function OnFileOperationComplete(fileOperationCompleteData)

	If fileOperationCompleteData.query Then
		DOpus.Output "query for action " & fileOperationCompleteData.action
		DOpus.Output "command: " & fileOperationCompleteData.cmdline
		if fileOperationCompleteData.action = "rename" Then OnFileOperationComplete = True
	ElseIf fileOperationCompleteData.action = "rename" Then
		DOpus.Output "rename complete!"
		Dim old
		For Each old in
			DOpus.Output "old: " & old
			DOpus.Output "new: " &
	End If

End Function

Hello Jon,
Thank you very much for the excellent support :smiley::+1:
I'll give it a try as soon as possible.
Have a great day and weekend.
Best wishes from Switzerland

Hello Jon,
Great! I tried it out and it works perfectly.
Thank you so much
Best regards and best wishes from Switzerland

1 Like