when moving a file into a folder, is it possible to move duplicates inside that folder?

I have an apple script which moves all files within a folder into a new folder according to the first 6 characters of the filenames. If the folder already exists, the files get moved into that existing folder instead. If the file already exists in the new/existing folder, the file to be moved into the folder gets a "copy" extension to the filename – which is not in the script, it's a system function ;-)

My question: **Is it possible to move all existing files into a subfolder (named "_alt" for example), before the other files get the "copy"-extension? **

This is my existing script:

set mgFilesFolder to (choose folder with prompt "Choose folder…")

(* get the files of the mgFilesFolder folder *)
tell application "Finder" to set fileList to files of mgFilesFolder

(* iterate over every file *)
repeat with i from 1 to number of items in fileList
    set this_item to item i of fileList
    
    set this_file_Name to name of this_item as string
    
    set thisFileCode to characters 1 thru 6 of this_file_Name as text
    log thisFileCode
    
    tell application "Finder"
        try
            set nf to make new folder at mgFilesFolder with properties {name:thisFileCode}
            
        end try
    end tell
end repeat

set sourceFolder to mgFilesFolder
set destinationFolder to mgFilesFolder

tell application "Finder"
   
   set the_files to (get files of mgFilesFolder)
    
    repeat with this_file in the_files

Replies

the file to be moved into the folder gets a "copy" extension to the filename

That behaviour is built in to the Finder and there’s no way to override it. What you can do is to check to see if a file with that name exists and then move it out of the way.

tell application "Finder"
	exists folder "Documents" of home
	-- true
	exists folder "Blibble" of home
	-- false
end tell

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"