I’ve been cobbling together a script that will count the amount of EPS files in a folder, then write this along with the date & time to a text file as a kind of log.
Here is what I have so far, can anyone help me at all? This is counting every single file in the folder (including sub folders which I don’t need). And I also can’t figure out how to narrow it down to a specific file type.
tell application "Finder"
set theFolder to (path to desktop as Unicode text) & "Completed"
set theList to do shell script "find " & (quoted form of POSIX path of theFolder) & " -type f | wc -l"
end tell
set filePath to (path to desktop as string) & "EPS Log"
try
set fileRef to open for access file filePath with write permission
set newText to ((current date) as string) & tab & "Total" & space & theList & return
write newText to fileRef starting at eof
close access fileRef
on error
try
close access file filePath
end try
end try
for a single folder level you can use System Events
tell application "System Events"
set theList to POSIX path of files of folder "Completed" of desktop folder whose kind is "Encapsulated PostScript"
end tell
set {TID, text item delimiters} to {text item delimiters, return}
set theList to theList as text
set text item delimiters to TID
set filePath to (path to desktop as text) & "EPS Log"
try
set fileRef to open for access file filePath with write permission
set newText to ((current date) as string) & tab & "Total" & space & theList & return
write newText to fileRef starting at eof
close access fileRef
on error
try
close access file filePath
end try
end try
Thanks Stefan, that does the job but it just creates a list of the files in the log rather than just the actual number of files which is all I need. Can it be tweaked to do that?
tell application "System Events" to set numberOfEPSFiles to count (get files of folder "Completed" of desktop folder whose kind is "Encapsulated PostScript")
set filePath to (path to desktop as text) & "EPS Log"
try
set fileRef to open for access file filePath with write permission
set newText to ((current date) as string) & tab & "Total" & space & numberOfEPSFiles & return
write newText to fileRef starting at eof
close access fileRef
on error
try
close access file filePath
end try
end try