Get File Extension from variable %TriggerValue%

Is it possible to get an extension from variable %TriggerValue% ?

I created a macro that renames files dropped on the folder into sequential files like:
image 001.jpg
image 002.jpg
image 003.jpg

I would like to make this macro flexible and use the extension of the file that is actually dropped not the “fixed” .jpg extension. Macro uses Folder Trigger “adds an item”. Regarding that I have another question: how should I use Move or Rename action that it does not create an error since the rename obviously triggers the action again: https://d.pr/i/QTqFXr

This is what the Split Path action is designed for.

It will split the path up in to component parts, including the baseman ("image 001") and extension ("jpg").

Note that currently it requires a full path, I will adjust it to work with just file names in the future, but if you are feeding it just a file name, add a slash at the front of the path like I have done in the example.

It is better to ask separate questions in separate topics - I nearly missed that question, and no one will look in this topic for the answer later.

The way I would deal with the issue would be to make the macro do nothing if the filename already matches the desired format. Ie, if the name already matches "[space]\d\d\d.", then do nothing.

WOAH that’s huge! I’m off to shorten a TON of macros now.

1 Like

Thank you, Split Path is very convenient, I was not aware of it.

I will split my questions in the future.

I’m not following that. Is “[space]\d\d\d.” a Regex statement?

Yes, although [space] is intended just to be a space character, but " \d\d\d." makes it hard to see the space. And there should be a backslash before the . as well.

In any event, the idea is to make the macro idempotent, so that if it is run twice on the same file, the second time will do nothing. That way it makes no difference if the action of the macro will cause the macro to be triggered again.

You may want to add a Semaphore Lock to the macro to ensure that the macro runs to completion before the next instance of the macro starts.

1 Like