n00b seeks to make file cataloguer

Hi all - I’m very new to Applescript (so far only needed it for extending Flash projectors to open files).

I’ve decided that I want to make a Filemaker Pro database (something I’m plenty experienced with) to catalog the files (not the folders) located on my CDs & DVDs. I know that disk catalogue apps exist, but none seem very flexible in terms of storing information other than what’s available in the file system.

So I’ll be created some related db’s to store a “CD” record in one DB, which is related to multiple “file” records in another DB. And then, thanks to FMP’s easy customization, I can add other information files about the files themselves (e.g. title, genre, medium, filename, summary, year, etc.). Once that’s in place it’ll be a snap to search for files by various criteria, sort, etc.

Where Actionscript comes in, I want to extend FMP by having an applescript which can recursively parse a disk’s enter automatically a “file” record for the given volume. I found a great head start in terms of a recursive directory crawler that increments a counter for every file it finds.

here’s its code:


property file_count : 0

set the_folder to (choose folder)
set file_count to 0
my count_files(the_folder, true)
return file_count

on count_files(the_folder, with_subs)
	set the_folder to the_folder as alias
	tell application "Finder"
		set the_files to files of the_folder
		set file_count to file_count + (count of the_files)
		if with_subs = true then
			set the_subfolders to folders of the_folder
			repeat with this_subfolder in the_subfolders
				my count_files(this_subfolder, with_subs)
			end repeat
		end if
	end tell
end count_files

Obviously the counter is incremented in this line

set file_count to file_count + (count of the_files)

however, I am totally not understanding the syntax required to access the filepath and filename and then append one or both to a list (is the & involved?). In theory I wouldn’t even need to do that if I simply swap in an FMP call to dump the filename to the new related record, but I wanted to see stuff in the event log to confirm I hooked in before trying to send data to another app.

If anyone has any tips on how to proceed, let me know! I’m not doing this for profit or anything (just a way to organize my life). I will be sharing it when complete.

I would recommend this code, which may be more appropriate for your needs:

on open aliasList
	repeat with i in aliasList
		processUnknownItem(i)
	end repeat
end open

to processUnknownItem(thisItem)
	if (thisItem as text) ends with ":" then
		processFolder(thisItem)
	else
		processFile(thisItem)
	end if
end processUnknownItem

to processFolder(thisFolder)
	--> you can manipulate this folder adding code here
	set itemList to list folder thisFolder without invisibles
	repeat with i in itemList
		processUnknownItem(alias ((thisFolder as text) & i))
	end repeat
end processFolder

to processFile(thisFile)
	--> you can manipulate this file adding code here
end processFile

If you save it as application, you can drop any file/folder, and it will process every file/folder within it.
If you are interested in files (for example), you can add code where it says “you can manipulate this file adding code here”. Eg:

set fInfo to info for (thisFile)
set fName to name of fInfo
set fSize to size of fInfo
--> do whatever with this info

fantastic! Thanks a ton for your help. I should hopefully be able to hobble out the few lines I’m looking for to fill in your gaps. Of course now a bunch of work has come in so I don’t have the down time to play much with this, but it’s something i really need since my disk binders are overflowing & need some way to manage them in a central DB.

Things are getting therre. I’ve gotten it to work, making a new FMP record in my “filenames” DB for every file it stumbles across. I ended up using a little of your code, but a lot of what I had originally since it seemed easier with what I originally found to just drop this into FMP as a “Perform AppleScript” item via ScriptEditor.

So, my current problem is that while it’s making a new record each time & inserting the file name every time, it’s not inserting the file name in the new records. And thus after running, I have the right number of records but only one with the field filled (since it simply updated itself each time).

Here’s where the code is at, currently:


 set the_folder to (choose folder) 
 my parseFilenames(the_folder, true) 
 
 on parseFilenames(the_folder, with_subs) 
    set the_folder to the_folder as alias 
    tell application "Finder" 
       set the_files to files of the_folder 
       repeat with the_file in the_files
            set fName to name of the_file 
            my enterFilename(fName)
       end repeat 
       if with_subs = true then 
          set the_subfolders to folders of the_folder 
          repeat with this_subfolder in the_subfolders 
             my parseFilenames(this_subfolder, with_subs) 
          end repeat 
       end if 
    end tell 
 end parseFilenames 


on enterFilename(someFile)
   tell document "filenames.fp5"
      tell window 1
         tell layout "default"
            go to it
            create new record at the end
            go to the last record
            set cell "filename" to someFile
         end tell 
      end tell
   end tell
end enterFilename

Any help activating the new record I’m making every loop through will be much appreciated!

duh.

just had to surround the “set cell” command who was dropping in the file name to do it to the current record.


            tell current record
               set cell "filename" to someFile
            end tell