Moving Processed Video Files

Hi! I was wondering if I could ask for some help with a project? I’m just really struggling with the syntax…

Here is the project:

sourceFolder - contains a hierarchy of sub-folders, the files in each sub-folder are numbered sequentially (e.g. "01_filename_a.m4v, 02_filename_b.m4v, etc.).

targetFolder - contains a sub-folder hierarchy that matches sourceFolder. I already have a script that will copy the folder structure of sourceFolder into targetFolder.

stagingFolder - a flat folder that contains the processed files (e.g. filename_a.m4v, filename_b.m4v, etc.) from sourceFolder, but without the “99_” prefix.

What I would like to do is for each of the files in the stagingFolder, find it’s path in the sourceFolder and it’s “99_” prefix, then add the “99_” prefix to the file/name in staging and move it to the matching folder in targetFolder.

Any help would be so greatly appreciated…

(I’m embarrassed to not have any code to post for the looping work.)

Sharon

Ok…here is what I have so far:


set stagingFolder to "Macintosh HD:Users:bob:Desktop:Staging:" as alias
set sourceFolder to "Macintosh HD:Users:bob:Music:iTunes:iTunes Media:TV Shows:" as alias
set targetFolder to "Macintosh HD:Users:bob:Desktop:TV Shows:" as alias

tell application "Finder"
	set theStagingFiles to every item of folder stagingFolder
	
	repeat with theFile in theStagingFiles
		set theFileName to the name of theFile
		set theWildCardFileName to "*" & theFileName
		
		set theSourceFile to do shell script "find " & quoted form of POSIX path of sourceFolder & " -iname " & quoted form of theWildCardFileName
		
		set x to POSIX file theSourceFile as alias
		set y to name of x
		set z to container of x
		
		--get the path from theSourceFile starting with 'TV Shows'
		--get the file prefix
		--move to target (starting with 'TV Shows')
	end repeat
end tell

My next job is to strip out the path I need from the source hierarchy. Any suggestions would be appreciated…