Hi everyone, I am trying to create a file rename using Regular Expression but just cannot get it to work? I am very new to Regular expression (obviously) and am trying to fumble my way through it. I want keyboard maestro to rename any files that are added to a folder. In this example I have added a file named SI-1911 - Cheat Sheet.pdf and want KM to change the name to 1911 - xxxxx So if I put 5 files into the folder they will be renamed with the four numbers and then - xxxxx In this example I have just one file in the folder named SI-1911 - Cheat Sheet.pdf and I want KM to rename it to 1911 - xxxxx.pdf Basically I just want KM to extract the number (1911), remove all the other text and put - xxxxx after the number.
$1 means the string that is captured within the first (and in this case, only) set of round brackets in the search string.
I hope I have understood your question correctly (you literally want the string "xxxxx", yes?). If not, please supply other examples of input names and desired output for each.
By the way, if the variable "Rename" is not needed outside your macro, you might want to make it a local variable (see "Scope" on the Wiki's page about Variables). If so, simply add "local " (or "local_" or anything beginning with "local" to the start of the variable name.
You might be on top of this, but apart from what @kevinb have already pointed out I also want to add that your macro in its uploaded state does not rename the files in the directory, it only renames the filename of the path stored in your global variable "Rename" (overwriting it for every iteration by the For Each).
Using KM11 you can rename files using the Rename a File action. Note that for it to work you need, in the bottom rename field, to specify a file name only, not a full path. There are many ways to obtain the file name from a full path within KM, and in the macro below I've added a filter action for this purpose.
Thank you, that fixed it. I would not have been able to work out what was going wrong and it took me hours to get to where I was but it was still not working! It's also great for me to learn and improve seeing how it works.