Note: The example bash script code is just that and does not contain any additional error handling as may be appropriate. The output of which would be, e.g.: Testing 20-10-03.zip # s = filename suffix (filename without prefix, space, and extension) The example bash script code uses shell parameter expansion to slice and dice the fully qualified pathname of the file(s) passed to it into the necessary pieces and then renames the file(s) using the mv command with the -n option, which will not overwrite an existing file, based on the values of the sliced and diced pieces of the fully qualified pathname.Īs coded, it uses a regex to only act on files that starts with two digits, followed by a dash, followed by two digits, followed by a dash, followed by two digits, followed by a space, followed by additional characters and a file extension, e.g.: 20-10-03 Testing.zipĮxample bash script code: # f = fully qualified pathname
Get Selected Finder Items or Get Specified Finder Items, and then add a Run Shell Script action. If you do just a Workflow, then you will need to add a Files & Folders action, e.g. You can create an Automator Workflow, or Service/Quick Action, workflow. I'll happily give further comment.Yes, one of the ways it can be done in Automator is by using a Run Shell Script action with the example bash script code shown further below. After that, we want to run (the same script or a different one) it to actually make the changes.Īll I need is stated above, so anything marked "MAKE -" needs to become a hyphen and anything marked "REMOVE" needs to just go away. This will allow us to review the results and make sure there are no stuff-ups. Basically I need to be able to run a script to output all the changes that will be made to a file, before anything is changed. There aren't any additional requirements. This means I have to use pure bash to perform the operation. The rename command is not available on our servers at all. I'm sure he has his reasons, but I can't say that I'm privy to them. I'm unable to use any version of rename, the head of my IT dept.
The script would then either need to be modified slightly to use mv instead, or it could refer to the file created using echo and perform all the necessary changes using it.Īny and all help would be appreciated as this is really rather important and I lack the skills at this point in time to make this myself.Ī final note, I can't use the #rename command.
Ideally the script would run the first time and produce a file using echo with all the changes that need to be made including the full path and then the changed path.
For example, I can create a script to remove only from file names, but I don't know how to include folders/directories nor do I know how to include all the other characters in this one script. I know how to make simple versions, that can only change file names on a case by case basis but can't do it en mass. This is a rather important step in a very large project we have going in our organisation, and I haven't been able to create a script thus far. If the character is flagged as "REMOVE" then it should be removed, and nothing be put in it's place, for example a file named John?Sykes.doc would become JohnSykes.doc REMOVE character with "MAKE -" next to it needs to be made a - (hyphen) in place of the character, for example a file named John\Sykes.doc needs to become John-Sykes.doc. I need an assist here, got a project going where we need to modify file & folder names within a specific directory in order to remove or replace any and all characters which would be considered illegal under Windows, with a few additional characters.