Delete Files and Folders in Selected Folder; Then Rename Files [Example] Macro (v9.0.6d2)

Use Case

  • Provide JavaScript RegEx Solution to Renaming Files since KM does NOT support using KM Variables in a RegEx Search and Replace Action.
    • Note that this JavaScript properly handles use of RegEx Options (like (?mi))
  • Show how to Filter List of Finder Items using RegEx
  • Provide Support in Developing and Testing RegEx Patterns
    • Open Regex101.com page loaded with data from Macro

This macro was built in response to How Do I Write a Macro to Delete folders and files within a given folder?


UPDATED: 2020-08-02 18:14 GMT-5

  • Added Regex Development and Test Support

Example Output

Finder Folder Before Macro Processing

image

Prompt to Confirm

RegEx Support

Regex101.com Page Opened Loaded with Data from Macro

Finder Folder After Processing

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Below is just an example provided to demo this functionality. You will need to use as an example and/or change to meet your workflow automation needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Delete Files and Folders in Selected Folder; Then Rename Files [Example]

-~~~ VER: 2.0    2020-08-02 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Delete Files and Folders in Selected Folder- Then Rename Files [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Delete Files and Folders in Selected Folder; Then Rename Files
    • Uses RegEx For Both Deletion Filter and Rename Criteria

HOW TO USE

  1. First, make sure you have followed instructions in the Macro Setup below.
  2. Select the FOLDER you want to Process
  3. Trigger this macro.
    • Prompt is Displayed to Review, Edit, or Confirm data
    • Additional Buttons to Open Regex101.com page loaded with Macro data
      • Prompt stays open until user selects "OK"

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .
      Make These Changes to this Macro
  1. Assign a Trigger to this macro.
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro, and the Macro Group it is in.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • CHANGE To RegEx Pattern to Match Files and Folders to Be Deleted
    • CHANGE to RegEx Pattern to Match Text in File Name to be Changed
    • CHANGE to RegEx Pattern for REPLACEMENT

REQUIRES:

  1. KM 9.0+ (may work in KM 8.2+ in some cases)
  2. macOS 10.11.6 (El Capitan)+

TAGS: @Files @Folders @Regex @Delete @Rename @Example

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

ACTION COLOR CODES

  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Variables or Clipboards,
    OR IF/THEN and PAUSE Actions

USE AT YOUR OWN RISK

  • While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

2 Likes

Just updated my OP and Macro to Ver 2.0.

Hopefully this will help those interested in RegEx learn how to use it.
Please feel free to post your questions.

@JMichaelTX as a developer and avid automator, I applaud your work :clap: But I have one little question: what is your use case for this macro? From screenshots, it seems to do something with video production and its assets management?

First, it is in response to another user's request:

So you might look there for more insight.

Second, as stated at the top of my post:

Did you have a question about that?

@JMichaelTX thank you kindly :slight_smile: I've read the Use cases block but no specific Use case came to my mind. The original question made it clearer – I actually realized that I'm manually doing something very similar when importing and processing photos & videos from multiple cameras.

1 Like

Do you have any suggestions on how to improve my stated use case that would be clearer to you, and others?

I guess it's good, it's just a very specific use case IMO.

Sorry for off-topic, but what tool do you use for bubble annotations in screenshots? I'm using Monosnap, but it doesn't support these :slight_smile: https://take.ms/Rtoa4

I use Snagit -- The Best Screen Capture and Annotation Software , if you need full featured annotations as well as quick screen recording. It is not cheap, ~$50, so will not be for everyone.
But I use it many times a day, and it is well worth the cost to me.

1 Like