File lists

Hi

I need some help on how to create a script that can be run on our server volumes to determine the following, and generate a text report on completion.

  1. Total number of files and folder on the server volume
  2. Files and folders older than a specific time (say 3 months) these are files and folders that have been on the server that have not changed in this time period
  3. Apply a color label to these folders and files for easy visual identification
  4. Work out how much disk space is used up by these files and folders
  5. Indicate what free disk space is left on the volume

We have around 1.5TB of disk space on our server, and users are incredibly bad at house keeping and archiving their work. A script like this would help identify files and folders that can be removed freeing up more disk space.

Thanks in advance

Malcolml

Model: MacBook
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi

You could run something like this for question number 1:

tell application "Finder"
	set c to entire contents of (choose folder)
	set a to count c
	display dialog a as string
end tell

It could take a while on a big volume (be warned!)

this is a script i borrowed :smiley: off Adam bell and adjusted it to my needs it labels folders on a drive
a different color that are over a certain size:

on run
	set folder_main to choose folder
	tell application "Finder"
		set fldrs to folders of (folder_main as alias) as alias list
		repeat with aFolder in fldrs
			if ((size of (info for aFolder)) div 1048576) > 150 then set label index of aFolder to 4
		end repeat
	end tell
end run

save as an application!!

Thanks for the post Pidge

Is there a way to get the first script to dump the resulting file list count into a text file?

Thanks

Malcolml

set deskPath to path to desktop as Unicode text
set filePath to deskPath & "countLog.txt"
set fileRef to (open for access file filePath with write permission)

tell application "Finder"
	set c to entire contents of (choose folder)
	set a to count c
end tell

write a to fileRef
close access fileRef

Hi james

For some reason that didn’t work for me but jiggling it around a bit did:

tell application "Finder"
	set c to entire contents of (choose folder)
	set a to count c
end tell
set deskPath to path to desktop as Unicode text
set filePath to deskPath & "countLog.txt"
set fileRef to (open for access file filePath with write permission)


write a to fileRef as string
close access fileRef

Hi,

for a large amount of files and folders the Finder is incredible slow to collect all data.
The find shell command is much faster and returns the POSIX paths of the found files and folders.
All invisble files and folders (starting with dot) are excluded in the script below.
For testing the line which changes the label color is commented out.

set theFolder to choose folder
set {TID, text item delimiters} to {text item delimiters, ":"}
set theDisk to text item 1 of (theFolder as string)
set text item delimiters to TID
set thePaths to paragraphs of (do shell script "find " & quoted form of POSIX path of theFolder & " ! -name '.*'")
set theCount to count thePaths

tell (current date) to set t to it - 90 * days
set fileSize to ""
repeat with i in thePaths
	set theItem to POSIX file i as alias
	set {f, m} to {folder, modification date} of (info for theItem)
	if m < t then
		if not f then set fileSize to fileSize + (size of (info for theItem))
		-- tell application "Finder" to set label index of theItem to 2
	end if
end repeat
set fileSize to ((((round (fileSize / 1.048576E+4)) / 100) as string) & " MB")
tell application "System Events" to set diskFreeSpace to ((((round ((free space of disk theDisk) / 1.073741824E+7)) / 100) as string) & " GB")

PS: the routine to write a report can do somebody else :wink: