need help for neurology web site using applescript

For a neurology web site I’m working on, I have a directory on my computer with several thousand research papers organized in a specific hierarchy. I was going to use PHP to dynamically create all the pages of the site, but the trouble with that is that I would have to upload the entire 3.5GB folder to my server, which is a waste because I don’t want to actually display the files. So I was hoping to use Applescript to take all the names of the files and output them in a certain specified way to a simple document that my to-be-developed PHP application will use. Does anyone know how I might be able to copy the names of nested files and folders and put them into a text file? Thanks so much.

This is very easy to do via AppleScript. The bigger question is the format of the output file.

You need to define what you want the output to look like so that people have a target to shoot at.

For example do you want a simple list of pathnames:


Or do you want it hierarchal:


That makes a big difference in how the script runs.

The thing about it is that I need the file to be interpretable (and useable) by a PHP script. So I need a way of not only identifying whether a particular item is a file or a directory, but also the relationships between them (for example, a file at the bottom of the hierarchy belongs to folders 5894, 2943, and 3894 in that order). I’d like to have applescript dynamically assign an ID number to each item, and then append to that number each ID of the level above it. The goal is that if I click on a link on the web page, the php script will identify the ID number of that link and then create a page with links for all the items that have that ID number in them. Sorry if that’s a bit confusing. So, let’s say that I have a filename whose applescript-assigned ID is 5459, and it is in the folder whose ID is 2939. In the textfile to be written to, the entry for that file should be 2939_5459::“filename”. The entry for the folder should be 2939::“foldername”.


If you are running OS X on your computer, and you know PHP, can’t you use PHP to generate the file locally and then upload it to your server?

You’re asking a lot from AppleScript when what you really want is a database. If I’m reading you correctly, you want to assign IDs to every folder and file but not change the names of any folder or file. When you select a file, your PHP script would look to the path of the file, get the name of the file and all of the folder names, use that to query your ID list, and return a list of IDs for every folder in the path to the file and the ID of the file itself. You could write an AppleScript that would build this DB for you, adding key pairs of folder paths and unique IDs and file paths and unique IDs and add it to a MySQL DB (or some other DB). That would be your best bet.


Jon–you’re saying that I shouldn’t use applescript? Or that I should?.. because if I get applescript to do all that I’m not sure why I would need to dive into MySQL, which I know little about. If i do need to use applescript, then I need help in both the areas of getting the filenames, as well as assigning IDs. Thanks so much…

I’m saying that you could use AppleScript to build your database but then you should use a real database connected to your site when you want to extract the data, don’t rely on some sort of flat file.

Here’s a script that will generate a list of unique IDs for files (and their paths) of a folder you choose. It will only add new folders and files if they are, in fact, new. This should get you going to establish the key pairs between a file or folder path and it’s unique ID. I would modify this to choose a master source folder, recursively go through the folder and generate the IDs, then add them to a real DB. The code below to get IDs for a file and its constituent folders is what you would port to your PHP script.