Simple folder walk...I think
Simple folder walk...I think
- Subject: Simple folder walk...I think
- From: "John Tuttle" <email@hidden>
- Date: Fri, 16 Aug 2002 09:17:13 -0500
I'm attempting to write a short script which will walk through a folder
which contains text files and other subfolders. When a text file is
encountered an action is performed on the file. The idea is to make changes
to all text files within all nested folders under the parent folder.
This seems to be a simple idea but I have run into problems.
I though that this operation would be a good candidate for a couple of
handlers; one to act on a text file when it is encountered and the other to
act on a folder when it is encountered.
The folder handler works (I think) but I get an error when the file handler
runs. Any ideas? The script is below, also, any constructive comments on
structure are welcome...lots to learn!
Thanks
Script:
set mytext to ""
tell application "Finder"
activate
--choose the parent folder
set myfolder to choose folder
--get a list of all items within the folder to process
set mylist to every item of myfolder as list
-- get an item count for the list for the repeat loop
set mycount to count items in myfolder
--begin repeat loop for every item in the parent folder
set x to 1
repeat mycount times
--grab the first item in the list
set myitem to item x of mylist
--determine if the item is a folder
set myclass to class of myitem
--if item is a folder run the folder handler, otherwise run the file
handler
if myclass = "folder" then
HandleFolder(myitem)
else
HandleFile(myitem)
end if
set x to x + 1
end repeat
end tell
-----
on HandleFolder(myitem)
set folderlist to every item of myitem as list
set foldercount to count items in myitem
set F to 1
repeat foldercount times
set myitem to item F of folderlist
set fi_class to class of myitem
if fi_class = "folder" then
my HandleFolder(myitem)
else
HandleFile(myitem)
end if
set F to F + 1
end repeat
end HandleFolder
----
on HandleFile(myitem)
end HandleFile
--
John Tuttle
_______________________________________________
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.