renaming a file

Hello,

I have this folder action which works fine but I need to have it rename the file (just add the .txt extension). Everything I tried has not worked. Here is the working script…

on adding folder items to thisFolder after receiving theseItems
repeat with aFile in theseItems
try
set tName to name of (info for (contents of aFile))
set myFile to “Volumes/HardDrive/folder/” & tName

		do shell script ("curl -T /Volumes/HardDrive/folder/" & tName & " [url=ftp://ftp.server.com/folder/)]ftp://ftp.server.com/folder/")[/url]
		
		move (contents of aFile) to "Volumes/HardDrive/archive/"
	end try
end repeat

end adding folder items to

I have no control of the file coming into the folder all I know is that it is a valid text file and I need to have the .txt extension added to the name. Script is running on 10.4.11.

Thanks for any help.

Hi,

works fine ;)? this

 move (contents of aFile) to "Volumes/HardDrive/archive/"

cannot work at all, only the Finder can move files and AppleScript expects HFS paths (colon separated).

The main problem is, renaming a file in a hot folder triggers the folder action again,
but if you want to move the file anyway, you can move and rename the file at the same time with the shell mv command


on adding folder items to thisFolder after receiving theseItems
    repeat with aFile in theseItems
        try
            set myFile to "Volumes/HardDrive/folder/" & name of (info for aFile) & ".txt"
            do shell script ("curl -T /Volumes/HardDrive/folder/" & tName & " [url=ftp://ftp.server.com/folder/)]ftp://ftp.server.com/folder/")[/url]
            do shell script "mv " & quoted form of POSIX path of aFile & space & quoted form of myFile
        end try
    end repeat
end adding folder items to

For openers, a couple of words of advice:

  1. You shouldn’t rename a file in a folder with an action because the new name is viewed as a new file, the action is triggered again, and an endless loop is spawned. Move it first, then rename it at its destination.

  2. Name is a property of a file that must be changed by the Finder.

I thought the same but it does move the file on my system.

Thanks for the help.
Kerry