Re: Modification date checker
Re: Modification date checker
- Subject: Re: Modification date checker
- From: kai <email@hidden>
- Date: Fri, 25 Mar 2005 02:03:18 +0000
On Thu, 24 Mar 2005 13:50:46 -0500, Alex Husted wrote:
I wrote this little script to check which files in a particular set of
folders have been modified in the time since the script was last run.
It
works fine, but never on the first try. The first time I run it, it
writes
the "error getting date" to the log because my try statement fails. If
I run
it immediately again it works fine, but since I am using the mod date
of
the log file as the record of when the script was last run, running it
twice
all the time is not an option.
any help would be much appreciated
Alex
global x
set x to false
global error_log
set error_log to "SomeNetworkWindozeDrive:New Project Mod Log.txt"
global modFiles
set modFiles to {}
global modDates
set modDates to {}
global lastCheck
tell application "Finder"
set theFolder to "SomeOtherNetworkWindozeDrive:New Projects
2005:"
as alias
set lastCheck to modification date of file error_log
my checkFiles(theFolder)
my mod_log(modFiles, modDates)
if x is true then
tell application "BBEdit"
activate
open error_log
end tell
end if
end tell
on checkFiles(theFolder)
tell application "Finder"
set theFiles to (every file of theFolder)
if (length of theFiles) > 0 then
repeat with i from 1 to (length of theFiles)
try
set modDate to modification
date of
item i of theFiles as date
--if (current date) -
(modDate) <
(86400) then
if modDate > lastCheck then
set x to true
set end of modFiles to
(name
of theFolder & ":" & name of item i of theFiles)
set end of modDates to
modDate
end if
on error
set end of modFiles to (name of
theFolder & ":" & name of item i of theFiles)
set end of modDates to "Error
getting date"
end try
end repeat
end if
set subfolders to every folder of theFolder
repeat with this_subfolder in subfolders
my checkFiles(this_subfolder)
end repeat
end tell
end checkFiles
on mod_log(modFiles, modDates)
try
open for access file error_log with write permission
write ((return & "Report completed: " & (current date)
as
string) & return) to file error_log starting at eof
if length of modFiles > 0 then
repeat with j from 1 to length of modFiles
write ((item j of modFiles) & tab &
(item j
of modDates) & return) to file error_log starting at eof
end repeat
end if
end try
try
close access file error_log
end try
end mod_log
While I didn't see the same errors as you, Alex, I was getting
inconsistent results. I found that getting the Finder to update the
target files seemed to resolve the problems. (Tested only on local
volumes.)
Here's a slightly reworked version that works here, and which also
avoids the use of global variables:
-------------
to check_files from theFolder against last_check
set mod_list to {}
tell application "Finder"
repeat with this_file in (get theFolder's files)
update this_file
set modDate to this_file's modification date
if modDate > last_check then set mod_list's end to theFolder's name
& ":" & this_file's name & tab & modDate
end repeat
repeat with this_subfolder in (get theFolder's folders)
set mod_list to mod_list & my (check_files from this_subfolder
against last_check)
end repeat
end tell
mod_list
end check_files
to log_entries from mod_list at error_log
try
set open_file to open for access file error_log with write permission
write (return & "Report completed: " & (current date) & return) to
open_file starting at eof
repeat with mod_entry in mod_list
write mod_entry & return to open_file starting at eof
end repeat
end try
try
close access open_file
end try
tell application "Finder" to update file error_log
end log_entries
set error_log to "SomeNetworkWindozeDrive:New Project Mod Log.txt"
set theFolder to "SomeOtherNetworkWindozeDrive:New Projects 2005:" as
alias
tell application "Finder" to set last_check to modification date of
file error_log
set mod_list to check_files from theFolder against last_check
log_entries from mod_list at error_log
if (count mod_list) > 0 then
tell application "BBEdit"
activate
open error_log
end tell
end if
-------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden