Dynamic Folder Location

Hi Folks-

I’m trying to write a script that will place a file in a given folder based on its file name (number). I have the whole script running except for the last bit, where the file location path is determined by a previously created string.

The line I’m having trouble with is:

duplicate vtheFile to vfullpath with replacing

The error I’m getting is:

There are multiple folders inside the ‘PDF Page Proofs’ folder that increment by 10,000. The full code of the script is:

to split(vsomeText, vdelimiter) --sets up delimiter
	
	set AppleScript's text item delimiters to vdelimiter
	
	set vsomeText to vsomeText's text items
	
	set AppleScript's text item delimiters to {""}
	
	return vsomeText
	
end split

on open of vdropList
	
	repeat with vtheFile in vdropList
		
		set vchosenFile to last item of split(vtheFile as string, ":") --only returns file name
		set vfilenumber to first item of split(vchosenFile as string, "_") as number -- only returns digits
		
		set vcompare to 10000
		repeat
			set vcompare to vcompare + 10000
			if vcompare > vfilenumber then exit repeat
			
		end repeat
		set vfolder to ((vcompare as integer) - 10000)
		set vtens to vfolder / 1000 as integer
		set vactualfolder to (vtens as string) & "," & "000"
		set vfullpath to "Users:SHARED:_PDF Page Proofs (low res):PDF Page Proofs:" & vactualfolder & "s"
		vfullpath as string
		tell application "Finder"
			duplicate vtheFile to vfullpath with replacing
		end tell
	end repeat
end open

thanks so much

Ralph Lindenfeld

Hi Ralph,

you cannot duplicate a file to a string
either

--
set vfullpath to ((path to users folder as Unicode text) & "SHARED:_PDF Page Proofs (low res):PDF Page Proofs:" & vactualfolder & "s") as alias
	tell application "Finder"
		duplicate vtheFile to vfullpath with replacing
	end tell
--

or

set vfullpath to (path to users folder as Unicode text) & "SHARED:_PDF Page Proofs (low res):PDF Page Proofs:" & vactualfolder & "s"
	-- vfullpath as string
	tell application "Finder"
		duplicate vtheFile to folder vfullpath with replacing
	end tell

does it

That works!!

Thanks SO much. I’m a complete Applescript newbie and this is my first working (useful) script.

-Ralph Lindenfeld