RE:script to delete files based on date in file name
RE:script to delete files based on date in file name
- Subject: RE:script to delete files based on date in file name
- From: email@hidden
- Date: Wed, 17 Jul 2002 02:06:37 EDT
The best way to do this, in my humble experience, is to use recursion of a
handler (i.e. - where a handler contains a call to itself, spawning another
copy to deal with each subfolder). Remember, when calling internal handlers
you have to use the prefix 'my' before the handler name (something not clear
in Apple's documentation). To work through an entire disk, select a disk icon
during the choose folder dialog box...
tell application "Finder"
set OurTarget to choose folder
my CleanMyFiles(OurTarget)
end tell
----------------+----------------+----------------+
-- HANDLER b IsFolder
-- Purpose: Determines if the current file is a folder (returns boolean)
-- Expected Input: String or alias of path&filename
-- Returns Output: Boolean, TRUE or FALSE
-- Calls NO other handlers
----------------+----------------+----------------+
local ValueForReturn -- boolean, Is path pointing at a folder?
local TheRecordContents -- record, the complete contents of the file record
on IsFolder(FullItemPathAndName)
set TheRecordContents to (get info for (FullItemPathAndName)) as list
-- item 7 in the list will be TRUE if it is a folder, FALSE if it is not
(boolean)
set ValueForReturn to (item 7 of (TheRecordContents)) as boolean
return ValueForReturn as boolean
end IsFolder
----------------+----------------+----------------+
-- HANDLER b CleanMyFiles
-- Purpose: Removes whatever files want to be deleted
-- Expected Input: String or alias of path&filename
-- Returns Output: Boolean, TRUE or FALSE
-- Calls: IsFolder
----------------+----------------+----------------+
local ListOFiles
local NumberOfFiles
local CurrentFileToCheck
local GenericLoopCounter
local NewRecursivePath
on CleanMyFiles(FolderToBeWorked)
set ListOFiles to list folder FolderToBeWorked
if ListOFiles is not {} then
set TotalCount to the count of items in ListOFiles
repeat with GenericLoopCounter from 1 to TotalCount
set CurrentFileToCheck to the (item GenericLoopCounter in ListOFiles as
string)
set CurrentFileToCheck to (((FolderToBeWorked & CurrentFileToCheck) as
string) as alias)
if (my IsFolder(CurrentFileToCheck)) then -- if current file is folder
set NewRecursivePath to (CurrentFileToCheck & ":")
-- go call this handler again with the new path
my CleanMyFiles(NewRecursivePath)
else -- if not a folder
-- // insert your code to test & delete appropriate files //
end if
end repeat
end if -- end if ListOFiles not empty
end CleanMyFiles
=-= Marc
>
I have searched for various ways, but they only deal with
>
one folder or one file based on modification date and that
>
doesn't always work correctly.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.