Automatically rename new files added to a specific folder

I see... This is interesting. Sounds like a lot is possible.

Yeah. Seems possible but out of my league to code on my own.

I got to look at this more… man… a lot here. I love it, though. BigUp to cyilmaz who made a super example to use right away. The example helps in understanding Script Add-in as well. BigUp to lxp, who made a great example of a concise way to traverse numbers in Directory Opus code. The example here probably has a lot of room for improvement. I only mean the little part I added. However, it seems to be working well. The regex can always be better. I have noticed that with certain file names with complex text strings, this can miss. BigUp to errante for pointing out that Directory Opus has this ability.

I am wondering what is even possible in server directories in an Opus lister. When combining scripting methods with the file handling ability Directory Opus has, its too good to be true!

**** Please note that using scripts like this and other things talked about here can reek havoc on you data. Do this at you own risk!
That being said try this...
autoNumImgfiles.js.txt (4.6 KB)
rename the file to autoNumImgfiles.js and see how to install and use it here...

nice, very nice, thank you.
but every time i put files in a watch fodler i got this error (after renaming):
image

(and it doesn't work on files with spaces)) )
P.S.
while I was playing with watch\unwatch, this error disappeared, but now unwatch button does not work, the script does not stop))
cuUnwatchFolder PATH "A:\123"

PPS
maybe that was in test mode) after restarting DOpus everything works fine

I cannot find the "Watch/Unwatch" button.
That is not mentionned anywhere. My setup is minimal and I got rid of most of the default toolbars.

You have to create the buttons.

The script description gives a couple of examples:

This script adds 2 commands: cuWatchFolder & cuUnwatchFolder with the same signature PATH/O

Use cuWatchFolder PATH Y:\ or cuUnwatchFolder PATH Y:\

See Raw Commands at the top of How to use buttons and scripts from this forum for how to put those commands into buttons.

So, I created both buttons with the single line of commands with the folder I want to watch / stop watching.
Added the scripts. Rebooted Dopus entirely.
Clicked the Watch button. Try pasting a file into the folder then.... Nothing. It didn't change anything. Is it because my folder is on a NAS?

But then, before posting the above, I added quotes around the PATH (ie. PATH "F:\folder name\") and now I get

 24 Mar. 2024 11:43 fsUtil.WatchChanges demo:  Error at line 97, position 5
 24 Mar. 2024 11:43 fsUtil.WatchChanges demo:  Invalid procedure call or argument (0x800a0005)

these errors...

Looking at line 97 at the file pctechtv posted, where it tries to access the cache variable in memory, you have probably clicked the Unwatch button before a Watch was triggered. If that's the case try starting a Watch first.

When I wrote the sample code, I wasn't focusing on making it bulletproof, but just demonstrating how the watchFolder & cancelWatchFolder methods work.

@pctechtv: if my suspicion above is correct, you might want to add this error-handling before line 97, something like:

// cuUnwatchFolder() - added - begin
if (!Script.vars.exists('cache')) {
    // unwatch triggered before watch - use a popup/dialog if you prefer
    $dbg('cache not initialized, probably no watch running');
    return;
}
// added - end
var cache = Script.vars.get('cache');

I will update the original script as such, too.

No. It does nothing. I clicked my "Watch" icon. The Script log didn't show anything new. Copied a jpg file in. Didn't do anything.

The two buttons are in a toolbar, above my directories tree:

image

And this is the "Scripts Management" window:
image

So, yeah. Nothing happens when I paste a new file in or save a new image into the folder, which the index currently sits at 2869 (so next image should be renamed to 2870.ext)

Because of the nature of the folder being highly personal, I'm not willing to make a video.

What I'm doing:

  1. Click my "Play" watch button.
  2. Copy a test jpg file from the root of mapped network drive F:. The original filename of this test file does not have a space.
  3. I paste the file into the watch folder.
  4. Nothing happens.

Well, I just went by the line 97, I haven't looked at the numbering logic at all.

Also I don't know if DOpus can watch NAS drives or not. Have you tried it with a local drive first?

Saying just in case, you can add as many watch/unwatch buttons for as many folders as you want obviously, so you can keep the existing buttons and duplicate them with new, local test paths.

It should work with NAS, as long as they send change notifications in general.

1 Like

I didn't at the time but now I did and it worked. Why?!

Anyway, I tested somewhere else on the F:\ drive and it worked as well.

But then I moved it in the same scenario as where the folders above are (there's a "!" in the path which is used in the fodler name to keep them on top of other folders) and... it didn't work anymore. Made double-sure the paths were fine... nope... Rebooted, clicked my button and tried again. Nope.

I'm entirely lost.

My NAS is a Synology DS1821+ NAS using the latest OS version. If that helps...

try changing the line at the top of the script from var DEBUG = false; to var DEBUG = true;. The script should show more information as to what it did last. I'm guessing it exits due to some check and you're not seeing it.

There you go:

24 Mar. 2024 18:26  Main process started.
 24 Mar. 2024 20:48 fsUtil.WatchChanges demo:  watching path: F:\[...]\script, id: 724d5acd4cb070d02d7ae7fe29596021
 24 Mar. 2024 20:48 fsUtil.WatchChanges demo:  OnFilesystemChange called
 24 Mar. 2024 20:48 fsUtil.WatchChanges demo:  change for watch id: 724d5acd4cb070d02d7ae7fe29596021, path: F:\[...]\script

"Script" is the test folder. Added a jpg file to it. It didn't rename and that's all it wrote above.

Can I see the full path of a file in the directory you are trying to use?

I won't say out exactly but there are two folders before this.

The first has two words from the English dictionnary, separated with a space (the space might be the issue, tbh). The second is a single letter. Then the "script" folder is in that single letter folder.

Indeed.

var cmdLine = "Rename IGNOREEXT " + item + " TO " + mxx

@pctechtv
Appreciate the help, could you maybe enhance on the variable names? I tried to follow your snippet but mdr, mnm, ptt, nnw, nna and far are names unseen for variables as of yet (by me), it's quite hard to understand without scrolling back and forth! o)

What does "mdr" stand for when you assign a path to that variable? MyDiRectory or what is the system behind your naming? far is FileARray maybe and ppt is.. well, I fail to come up with something for that. o)

ps: Using just Powershell and FileSystemWatcher worked for me to watch folders in the past (so you do not rely on DO running/existing on the computer). It's free to use, you still need to write some code of course, but's lot's of examples out there, like this (and there are dozens more):

In the script, it was already this. So, that does not change anything.

You probably want something like this to wrap the full paths/filenames into double quotes.