Jump to content
Maurice

Cataloging your archived files

Recommended Posts

You can import a complete folder listing in a textfile with TextWrangler (http://www.barebones.com/products/textwrangler/): open a new textfile an choose Edit -> Insert -> Folder Listing. All files and subfolders are listed.

 

Does anyone know a free alternative to DiskTracker or Disk Library?

Edited by Maurice

Share this post


Link to post
Share on other sites

I believe that listener James wanted a means to put Finder file information into a form he could use from, say, Excel. What I am about to say may not be popular, but this looks like a job for Applescript. You can write your own script using the Script Editor application in Applications/Applescript. Here's roughly how:

 

The Finder info for each file in a folder or folder tree is accessible within a "tell block", e.g.

repeat with theFile in aFileList

tell application "Finder"

set theFileName to name of theFile

set theCreationDate to creation date of theFile

...

end tell

-- put instructions to move the data where you want it here. See examples below.

end repeat

 

Then the info can be sent to Excel or any Applescript-aware application (which show up in the list you see when you access File/Open Dictionary...). I don't have Excel (I use AppleWorks or OpenOffice now but I've used it much in the past), so I can't give a concrete example here, but here are two options: (1) send the data items directly to cells in the spreadsheet, or (2) write the data items to a tab- or comma-delimited text file which Excel can import. The first alternative would use a tell block similar to the above:

tell application "Excel"

set cell 1 of row 1 of document 1 to theFileName

set cell 2 of row 1 of document 1 to theCreationDate

...

end tell

 

The second text file alternative would use the File Read/Write commands found in the dictionary of the Standard Additions (again from File/Open Dictionary). No tell block is needed. It would roughly look like:

set theFileRef to open for access file myFileName

write theFileName & tab to theFileRef

write theCreationDate & tab to theFileRef

...

write theLastItem & return to theFileRef

close theFileRef

 

While it's true that scripting, like any programming language, can be a little intimidating at first, I think it is well worth the effort. Then your Mac will do exactly what you want it to do.

Share this post


Link to post
Share on other sites

Here is a hack from a listener (Greg) using the Terminal and TextWrangler or TextMate:

This technical and defintiely a hack, but it does work:

 

1) I use TextMate as my text editor. The free TextWrangler will also work in this example.

 

2) Using the cd command (e.g. cd /Volumes/DVD) In the terminal, go to the directory or volume to catalog. The CD in Jamie's case.

 

3) If you want an index of the files in the current directory, type the command:

ls -l > ~/disk.txt

If you want an index of the files in all directories below the current one (recursively), type the command:

ls -lR > ~/disk.txt

 

4) This will create a file called disk.txt in your home directory.

 

5) Open disk.txt in your text editor (TextWrangler or TextMate).

 

6) Using the ability of either program to cut squares of text, cut out everything before the date.

 

7) Using the same ability, cut out the date and paste it into a spreadsheet column, repeat with the file name in a separate spreadsheet column -- assuring you have the same number of lines so they match up when in the spreadsheet.

Share this post


Link to post
Share on other sites

Listener Scott offered yet another UNIX terminal solution:

Using the shell script below, you can get a list of files in a directory suitable for importing into Excel. If you store the shell script as "ctlg" in a directory (I have a ~/bin on every system I use), make it executable, and make sure ~/bin is in your PATH variable, it would work like:

 

shell_prompt$ ctlg [directory]> output_file

 

Where:

[directory] is the directory to create a catalog of. If none is given, the current directory is assumed.

output_file is where the comma separated values file would be stored

 

So... if I do "ctlg > catalog.csv" I will create a file name catalog.csv in my current directory with the information in the current directory. However, the file "catalog.csv" will be listed in that file.

 

The output format will be as follows:

 

"File name",size,year,month,day,time

 

Where the size is in bytes and the date/time is the creation time as reported by ls.

 

This assume that there are only files on the disk with no directories. If something more is needed, then a better script will have to be written. However, this was a quick and dirty hack from a long-time UNIX hacker!

 

#!/bin/bash
[ -n "$1" -a -d "$1" ] && cd $1
ls -lT | while read l
do
	[ ${l:0:5} = "total" ] && continue
	fname=${l:56}
	date=(${l:35:20})
	sz=($l)
	echo \"${fname}\",${sz[4]},${date[3]},${date[0]},${date[1]},${date[2]}
done

Share this post


Link to post
Share on other sites

If you just need a "quickie" solution, you could open a terminal and just use "ls".

 

Change to the directory with the files (cd /Users/myname/Desktop/directory)

 

then

 

ls > textfile.txt - will give you a textfile of the filenames only

 

You could use any of the modifiers for ls to format or choose what you want displayed.

Just man ls for all of the options.

 

This is not as full featured as the other solutions but is quick and easy.

Share this post


Link to post
Share on other sites

I just checked and--at least in 10.4.8--the shell scripts won't work correctly. For some reason, none of the shell utilities return creation time. Applescript is the only way I could figure it out. Well, that and Automator. :D

 

So, make an Automator workflow that picks out all the files you want, I used:

--"Get Specified Finder Items" -- Pointing at a folder/disk/whatever

--"Get Folder Contents" -- Check Repeat for each Subfolder if you need that

--"Run Applescript" -- With following script:

on run {input, parameters}
set theReturnData to {}
tell application "Finder"
	repeat with theFile in input
		-- The output data is built here. Just use whatever
		-- pieces of info you need separated by:
		--	 & (ASCII character(9)) &
		-- ASCII character 9 is a tab for those that don't
		-- read ASCII. :)
		--
		-- Some properties are:
		--	creation date
		--	modification date
		--	size
		--	comment
		--	displayed name
		--	name
		-- There are a bunch more. See the entry for "item"
		-- in the Finder's dictionary. You can get to it from
		-- Script Editor. And remember, the next line has to
		-- all stay on one line in the editor or be separated by
		-- Option+Return characters.
		set the end of theReturnData to (the displayed name of theFile) & (ASCII character (9)) & (the creation date of theFile) & (ASCII character (10))
	end repeat
end tell
return theReturnData as text
end run

--"Copy to Clipboard" or "New Text File"

 

The final output is tab-delimited. Should be fairly trivial to get it into a database from there.

 

--James

Share this post


Link to post
Share on other sites

  • Recently Browsing

    No registered users viewing this page.

  • Who's Online (See full list)

    There are no registered users currently online

×