rename contents based on folder name and duplicate

Hello all.

I am quite new to apple scripting so please forgive my ignorance. I have searched the forums so far and found some useful information concerning my file renaming issues but can’t modify it to my needs, and it’s something I can’t automate via automator. Here is the scenario… or better yet here is what I’m trying to achieve:

before:

after:

so what has happened is:

  • the files in the first folder level were renamed to include the folder name; and
  • a copy was made of the files and placed into the “working” folder but without a change to the filename.

If this were for one or two files this would not be an issue, but given that this has to happen for hundreds of files, it’s quite repetitive. any clues?

colly

Model: iMac
Browser: Firefox 18.0
Operating System: Mac OS X (10.6)

Hi,

give this a try:

starting point is your ‘this issue’-folder

global myFolder

set myFolder to choose folder with prompt "please choose the folder or directory" without invisibles
set recentFiles to do shell script "find " & (quoted form of POSIX path of myFolder) & space & " \\! -name '.*' -type f "

set filePathList to paragraphs of recentFiles
set TID to AppleScript's text item delimiters

repeat with i from 1 to count of filePathList
	set AppleScript's text item delimiters to {"//"}
	set currItem to text item 2 of (item i of filePathList)
	set AppleScript's text item delimiters to {"/"}
	if (count of text items of currItem) is 2 then
		set folderName to text item 1 of currItem
		set fileName to text item 2 of currItem
		set AppleScript's text item delimiters to {folderName}
		if ((count of fileName) is equal to (count of (text item 1 of fileName))) then
			my doMove(folderName, fileName)
		end if
	end if
	
end repeat

set AppleScript's text item delimiters to TID

on doMove(folderName, fileName)
	set origPath to (myFolder as text) & folderName & ":" & fileName
	set workingPath to (myFolder as text) & folderName & ":" & "working:" & fileName
	set changePath to (myFolder as text) & folderName & ":" & folderName & "_" & fileName
	
	do shell script "cp -f " & quoted form of POSIX path of origPath & space & quoted form of POSIX path of workingPath
	do shell script "mv -f " & quoted form of POSIX path of origPath & space & quoted form of POSIX path of changePath
end doMove

that did the trick! nice one!!!

many thanks

Colin

:wink:

cdFlash = same user as in adobe forums¿

yes, same as in the Adobe forums :smiley:

With a bit coding work, this could have also be done in Adobes ExtendScript :wink: