Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pierre1610

macrumors regular
Original poster
Feb 3, 2009
185
19
I want to be able to run a script that deletes files based on a defined version number.
Version number is written as “v01a”
EXAMPLE
1020_Project_Name_M001_File_Name_v01a.psd
1020_Project_Name_M001_File_Name_v01b.psd
1020_Project_Name_M001_File_Name_v01c.psd
The number will also change
1020_Project_Name_M001_File_Name_v02a.psd
1020_Project_Name_M001_File_Name_v02b.psd
1020_Project_Name_M001_File_Name_v02c.psd

- I want it to keep the last 2 versions.
- Searches all sub folders for files

Any ideas how i can do this?
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
Thanks for the info. Any idea how to do this in shell script or AppleScript?

Yep. You can search files and all sub folders quite easily with something like this in the Terminal.

Code:
find /path/to/your/folder/ -type f -name "*v[0-9][0-9][a-z].psd"

You'd then need to get a list of all the unique file "base names" e.g. 1020_Project_Name_M001_File_Name, then for each one get a list of the remaining file name part (e.g. v01a), sort, then delete as appropriate.
 

pierre1610

macrumors regular
Original poster
Feb 3, 2009
185
19
Yep. You can search files and all sub folders quite easily with something like this in the Terminal.

Code:
find /path/to/your/folder/ -type f -name "*v[0-9][0-9][a-z].psd"

You'd then need to get a list of all the unique file "base names" e.g. 1020_Project_Name_M001_File_Name, then for each one get a list of the remaining file name part (e.g. v01a), sort, then delete as appropriate.

I tried running this in terminal with subsitited paths but nothing happened

What would the rest of it be written in then?
 

pierre1610

macrumors regular
Original poster
Feb 3, 2009
185
19
Well, that's shell script so you could run it directly in Terminal (copy and paste, but obviously change the folder path). Or you could run it from an AppleScript. Or using Automator's "run shell script" action. Up to you!
Yeah i did copy and paste and change folder path but nothing happened. just got a '>' on the next line
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.