move f to alias fullpath with REPLACING fails

(Some of you have seen this script before but now I have a different question)

This script does the following:

drop a file on the folder “Sort”
the file will be moved to a subfolder that has the name of the file’s extension.
If the subfolder does not exist, then create is.
(files without an extension are moved to folders named Classic filetype)

Example:
foto.jpg goes into the subfolder “jpg”
If folder “jpg” does not exist, then create it.

Everything works fine!

Just one little thing:

if the file foto.jpg allready exists in folder “jpg” then it should be overwritten!
But this does not happen. It ends up in the folder “Sort” !

Why does “move f to alias fullpath with replacing” not work???

on adding folder items to this_folder after receiving added_items
		
	set thepath to this_folder as string
	copy thepath to basepath
	repeat with f in added_items
		set this_info to info for f
		if not folder of this_info then
			set fstring to f as string
			set olddelimiters to AppleScript's text item delimiters
			set AppleScript's text item delimiters to {"."}
			set extstring to get last text item of fstring
			set AppleScript's text item delimiters to olddelimiters
			if extstring = fstring then -- there is no extension
				set extstring to ("Classic " & file type of this_info)
			end if

			set fullpath to basepath & extstring
			try
				move f to alias fullpath with replacing -- REPLACING does not work!!!!!
			on error -- if there is no folder, then make the folder
				tell application "Finder" to set x to make new folder at this_folder with properties {name:extstring}
				move f to alias fullpath
			end try
		end if
	end repeat
end adding folder items to

Hello,

I had the same problem with my machine
You can try to do it with do shell script

replace your

 move f to alias fullpath with replacing 

for

 do shell script "mv -f "& (POSIX path of f) & " " & (POSIX path of alias fullpath)

To know more, type in your terminal “man mv”. You will get the full manual of moving file or directories

It worked with me

Thanks, DJ !

This script works fine, but chokes on files with spaces in the name:

I run into the error part of:

try 
            do shell script "mv -f "& (POSIX path of f) & " " & (POSIX path of alias fullpath)
         on error errormsg-- if there is no folder, then make the folder 
            tell application "Finder" to set x to make new folder at this_folder with properties {name:extstring} 
            move f to alias fullpath 
         end try 

The file being moved is called “vml bu.lll”

errormsg returns:
“mv: rename /Users/vml/Desktop/sort/vml to /Users/vml/Desktop/sort/lll/vml: No such file or directory
mv: rename bu.lll to /Users/vml/Desktop/sort/lll/bu.lll: No such file or directory”

mv treats “vml” and “bu.lll” as different files!

The script then runs into the error part of the try statement and attempts to make a new folder (which allready exists) and generates another error:
Finder got an error: This operation cannot be finished because an object of that name allready exists. (translated from Dutch error).

Boy this is becoming complicated!
Only because “move …with replacing” has a bug apparently.