Newbie needs info/help

Hi…

I use OSX predominantly, but still can use OS9. I’m involved in a project where I will have to translate lots of Audio Sample files to another format.

[b]Here’s what I need to do with an applescript.

  1. perform a find, specifying a certain folder and subfolders for the search, and specifying only that the file contains the extension “.exs”
  2. Move all the files found in step one to a different specified folder. (In the process they will be removed from many subfolders)

(optional but helpful step) find all resulting folders within the specified folder that are empty, and delete them

Sure would appreciate any help!

Thanks,

Stefan Garr[/b]

Remarkably simple:

property destFolder : "Macintosh HD:Dest Files"
set sourceFolder to "Macintosh HD:Source Files"

moveFilesFrom(sourceFolder)

on moveFilesFrom(thisFolder)
	tell application "Finder"
		-- use a 'try' statement since the get files line will throw an error if no files found
		try
			set theFileList to every file of folder thisFolder whose name contains ".exs"
			repeat with aFile in theFileList
				move file eachFile to folder destFolder
			end repeat
		end try
		-- now check for sub-folders:
		-- again, use 'try' since the get will fail if there are no sub folders
		try
			set theFolderList to every folder of folder thisFolder
			repeat with subFolder in theFolderList
				-- if we have a subfolder, recursively call ourselves
				my moveFilesFrom(subFolder as string)
				--now check if the folder is empty
				if number of files in folder (subFolder as string) = 0 then
					delete folder subFolder
				end if
			end repeat
		on error theErr
			display dialog theErr & " occured when processing " & name of subFolder
		end try
	end tell
end moveFilesFrom

Note the code isn’t heavily tested (since I don’t have a folder full of .exs files), but it should be pretty easy to work out any parts that don’t work.

Camelot’s code could probably be even more specific with:

set theFileList to every file of folder thisFolder whose name ends with ".exs"

Or, on OS X, this also seems to work. I’m not sure if pre-OS X Finders knows about name extensions.

set theFileList to every file of folder thisFolder whose name name extension is "exs"

:slight_smile:

… ahh, except for the fact that the original spec stated:

specifying only that the file contains the extension “.exs”

so I was only doing as asked. :wink:

I, too, can’t be sure about file extensions in Finder 9.x. It’s been so long since I’ve used pre-OS X systems I’ve forgotton.

:slight_smile: