0

I've been searching a lot for a script like this but I can't find it. I suspect it's similar to this

but not exactly, and I'm not sure how to modify it to work for me.

I have a group of files with multiple names like this....

File Name Vyear #01 (year).ext

FileName Vyear #01 (year).ext

and so forth, the convention is always the same.

Filename (sometimes multiple words) followed by V for Version then the year in parenthesis then followed by a number then another year in parenthesis. It's complicated but it's all there for a reason. What I'm looking for is a way to automate moving all those files into subfolders based on only the first part of that name. So that a file like this...

The Mist V2000 #01 (2011).zip

Would get moved to a folder named this.

The Mist V2000

I'm constantly having to make files like this and I'd love to get them sorted into sub-folders. My problem is that I'm not sure how to select just the first of the name (an account for files that have two or three words in the title) and the volume number only to create the subfolder and then match the filenames for the move.

I hope I'm explaining this properly. If anyone could help I would appreciate it.

Cheers.

1 Answer 1

0

Try this. Basically we can calculate the folder name if we know where the "#" character is in the file name. Then we can get all of the text up to there - 2 characters. Then you just have to make that folder and move the file into it. Simple. Good luck.

set sourceFolder to choose folder

tell application "Finder"
    set theFiles to files of sourceFolder

    repeat with aFile in theFiles
        set fileName to name of aFile

        if fileName contains "#" then
            set poundOffset to offset of "#" in fileName
            set folderName to text 1 thru (poundOffset - 2) of fileName

            set newFolder to (sourceFolder as text) & folderName & ":"
            if not (exists folder newFolder) then
                make new folder at sourceFolder with properties {name:folderName}
            end if

            move aFile to folder newFolder
        end if
    end repeat
end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.