Can't get every document file of every folder of startup disk ( SOLVED )
Can't get every document file of every folder of startup disk ( SOLVED )
- Subject: Can't get every document file of every folder of startup disk ( SOLVED )
- From: Bill Hernandez <email@hidden>
- Date: Tue, 19 Dec 2006 23:39:23 -0600
On Dec 19, 2006, at 1:01 PM, deivy petrescu wrote:
Bill, what these error messages mean is that there are no files
whose name contains .txt in that folder.
I've just run a script and got this error:
"Finder got an error: Can't get Name of every document file of
every folder of alias
"BuiaBuio:Users:deivy:Desktop:Ex_Dtop_folder:" whose Name starts
with "Z"."
But if I change "Z" with "A", I get the desired result.
Hope this helps.
Deivy
(*
Deivy,
-- You can copy this whole email and run it. It is Applescript
friendly..
-- Let me know what you think of all my notes, or if you find
anything you don't agree with...
-- (test = 1), (test = 2), (test = 3), (test = 4) all failed
-- (test = 5), (test = 6) worked perfect...
I ran a number of tests and documented everything that I found.
It turned out to be very interesting.
Thank You very much for all your insights, and help. I am gald
you did not give up.
I would have never figured out without all your help...
Best regards,
Bill Hernandez
Plano, Texas
This is the folder hierarchy I used for the tests . You can see
that there are three files
whose name contains ".txt", and two files whose creator is
"MSIE", the main folder, and a subfolder
A_TEMP <-- folder
A_msie_file.html <-- Creator "MSIE"
A_text_file_01.txt <-- Creator ""
A_text_file_02.txt <-- Creator ""
B_TEMP <-- folder
B_msie_file.html <-- Creator "MSIE"
B_text_file.txt <-- Creator ""
*)
set folder_ref to alias "HardDisk:Users:Bill:Desktop:A_TEMP:"
--> alias "HardDisk:Users:Bill:Desktop:A_TEMP:"
-- ( 1 ) this only searches A_TEMP for matching files, but does not
search any folders of A_TEMP
tell application "Finder" to set aLists to get (every document file
of folder_ref) whose creator type is "MSIE"
--> document file "A_msie_file.html" of folder "A_TEMP" of folder
"Desktop" of folder "Bill" of folder "Users" of startup disk of
application "Finder"
-- ( 2 ) this searches ONLY the folders of A_TEMP for matching files,
so it searches B_TEMP for matching files, but not A_TEMP itself
-- when you think of it, AS is doing exactly waht we are telling it
to do. We are telling it to get
-- every file of every folder, but not every file of itself, so it is
being very precise about what
-- it is being told to do.
tell application "Finder" to set aLists to get (every document file
of (every folder) of folder_ref) whose creator type is "MSIE"
--> document file "B_msie_file.html" of folder "B_TEMP" of folder
"A_TEMP" of folder "Desktop" of folder "Bill" of folder "Users" of
startup disk of application "Finder"
-- ( 3 ) in order to get the desired results I had to combine ( 1 )
and ( 2 )
tell application "Finder" to set aLists to (get (every document file
of folder_ref) whose creator type is "MSIE") & (get (every document
file of (every folder) of folder_ref) whose creator type is "MSIE")
--> document file "A_msie_file.html" of folder "A_TEMP" of folder
"Desktop" of folder "Bill" of folder "Users" of startup disk of
application "Finder"
--> document file "B_msie_file.html" of folder "B_TEMP" of folder
"A_TEMP" of folder "Desktop" of folder "Bill" of folder "Users" of
startup disk of application "Finder"
-- ( 4 ) which is basically the same as ( 3 ) using 5 lines instead
of 1 line, but much easier to read, and to comment
tell application "Finder"
set aLists to {} -- this step could be skipped, but makes the
next two lines easier to read for someone starting out
set aLists to aLists & (get (every document file of folder_ref)
whose creator type is "MSIE") -- ( 1 ) this searches only the files
of A_TEMP
set aLists to aLists & (get (every document file of (every
folder) of folder_ref) whose creator type is "MSIE") -- ( 2 ) this
searches only the folders of A_TEMP
end tell
-- ( 5 ) this step fails to convert the list to an alias list
tell application "Finder" to set aLists to (get (every document file
of (every folder) of folder_ref) whose creator type is "MSIE") & (get
(every document file of folder_ref) whose creator type is "MSIE") as
alias list
--> document file "B_msie_file.html" of folder "B_TEMP" of folder
"A_TEMP" of folder "Desktop" of folder "Bill" of folder "Users" of
startup disk of application "Finder"
--> document file "A_msie_file.html" of folder "A_TEMP" of folder
"Desktop" of folder "Bill" of folder "Users" of startup disk of
application "Finder"
-- ( 6 ) this converts the container method of returning lists, to
alias lists. Why Apple ever did something so strange is hard to
understand ?
tell application "Finder"
set aL to {}
repeat with theItem in aLists
set aL to aL & (theItem as alias)
end repeat
end tell
--> alias "HardDisk:Users:Bill:Desktop:A_TEMP:B_TEMP:B_msie_file.html"
--> alias "HardDisk:Users:Bill:Desktop:A_TEMP:A_msie_file.html"
-- ( 1 ) this only searches A_TEMP for matching files, but does not
search any folders of A_TEMP
tell application "Finder" to set aLists to get (every document file
of folder_ref) whose name extension is "txt"
--> document file "A_text_file_01.txt" of folder "A_TEMP" of folder
"Desktop" of folder "Bill" of folder "Users" of startup disk of
application "Finder"
--> document file "A_text_file_02.txt" of folder "A_TEMP" of folder
"Desktop" of folder "Bill" of folder "Users" of startup disk of
application "Finder"
-- ( 2 ) this searches ONLY the folders of A_TEMP for matching files,
so it searches B_TEMP for matching files, but not A_TEMP itself
tell application "Finder" to set aLists to get (every document file
of (every folder) of folder_ref) whose (name extension) is "txt"
--> document file "B_text_file.txt" of folder "B_TEMP" of folder
"A_TEMP" of folder "Desktop" of folder "Bill" of folder "Users" of
startup disk of application "Finder"
-- ( 3 ) in order to get the desired results I had to combine ( 1 )
and ( 2 )
tell application "Finder" to set aLists to (get (every document file
of (every folder) of folder_ref) whose name extension is "txt") &
(get (every document file of folder_ref) whose name extension is "txt")
--> document file "B_text_file.txt" of folder "B_TEMP" of folder
"A_TEMP" of folder "Desktop" of folder "Bill" of folder "Users" of
startup disk of application "Finder"
--> document file "A_text_file_01.txt" of folder "A_TEMP" of folder
"Desktop" of folder "Bill" of folder "Users" of startup disk of
application "Finder"
--> document file "A_text_file_02.txt" of folder "A_TEMP" of folder
"Desktop" of folder "Bill" of folder "Users" of startup disk of
application "Finder"
-- --------------------------------------------------
-- ERROR EXPLANATIONS, AS I SEE THEM
-- --------------------------------------------------
-- ( A ) where AppleScript chokes is when you tell it to do a
compound statement (a get, and a set)
-- on the same line, and that is why I was getting all the
errors, the solution appears to be a
-- "get ..." followed by a repeat loop to do the "set ..."
-- --------------------------------------------------
-- ( B ) it does the "get..." part OK, but dies on the "set..."
part, and throws the error...
-- --------------------------------------------------
-- ( C ) which explains why (test = 1), (test = 2) below both fail.
-- --------------------------------------------------
-- ( D ) (test = 3), (test = 4) below fail for three reasons
-- ( a ) the syntax is all wrong
-- ( b ) we are telling it to get the list as an "alias list"
-- ( c ) In retrospect, I think the main error was really
caused by the fact that I got the list with "Sel", and processed it
with "aSel", a huge TYPO that I just caught...
-- --------------------------------------------------
-- this fails because of ( A ), ( B )
-- tell application "Finder" to set the creator type of ((get (every
document file of (every folder) of folder_ref) whose (name extension)
is "txt") & (get (every document file of folder_ref) whose name
extension is "txt")) to "sfri"
--> Can't set «class fcrt» of {
--> «class docf» "B_text_file.txt" of «class cfol» "B_TEMP" of «class
cfol» "A_TEMP" of «class cfol» "Desktop" of «class cfol» "Bill" of
«class cfol» "Users" of «class sdsk» of application "Finder",
--> «class docf» "A_text_file_01.txt" of «class cfol» "A_TEMP" of
«class cfol» "Desktop" of «class cfol» "Bill" of «class cfol» "Users"
of «class sdsk» of application "Finder",
--> «class docf» "A_text_file_02.txt" of «class cfol» "A_TEMP" of
«class cfol» "Desktop" of «class cfol» "Bill" of «class cfol» "Users"
of «class sdsk» of application "Finder"
--> } to "sfri".
-- this fails because of ( A ), ( B )
-- tell application "Finder" to set the creator type of (every
document file of (every folder) of folder_ref) whose (name contains
".txt") to "R*ch"
--> Finder got an error: Can't set creator type of every document
file of every folder of alias "HardDisk:Users:Bill:Desktop:" whose
name contains ".txt" to "R*ch".
-- (test = 1), (test = 2), (test = 3), (test = 4) all failed
-- (test = 5), (test = 6) worked perfect...
set test to 6
if (test = 1) then
tell application "Finder"
set folder_ref to (choose folder)
-- this fails because of ( A ), ( B ), ( D )( a )
set the creator type of (every document file of (every folder
of folder_ref)) whose (name contains ".txt") to "R*ch"
end tell
-- Finder got an error: Can't set creator type of every document
file of every folder of alias "HardDisk:Users:Bill:Desktop:" whose
name contains ".txt" to "R*ch".
end if
if (test = 2) then
tell application "Finder"
set folder_ref to ((choose folder) as text)
open folder folder_ref
-- this fails because of ( A ), ( B ), ( D )( a )
set the creator type of (every document file of (every folder
of folder folder_ref)) whose (name contains ".txt") to "R*ch"
end tell
-- Finder got an error: Can't get every folder of
"HardDisk:Users:Bill:Desktop:".
end if
if (test = 3) then
tell application "Finder"
set folder_ref to (choose folder)
open folder folder_ref
-- this fails because of ( A ), ( B ), ( D )( a ), ( D )( b )
-- In retrospect, I think the error was really caused by the
fact that I got the list with "Sel", and processed it with "aSel", a
huge TYPO that I just caught...
set Sel to get ((every document file of (every folder of
folder_ref)) whose (name contains ".txt")) as alias list
repeat with theItem in aSel
set the creator type of theItem to "R*ch"
end repeat
end tell
-- Finder got an error: Can't get every folder of
"HardDisk:Users:Bill:Desktop:".
end if
if (test = 4) then
tell application "Finder"
set folder_ref to (choose folder)
open folder folder_ref
-- this fails because of ( A ), ( B ), ( D )( a ), ( D )( b )
-- In retrospect, I think the error was really caused by the
fact that I got the list with "Sel", and processed it with "aSel", a
TYPO that I just caught...
set Sel to get ((every document file of (every folder of
folder_ref)) whose (name extension is "txt")) as alias list
repeat with theItem in aSel
set the creator type of theItem to "R*ch"
end repeat
end tell
-- Finder got an error: Can't get every folder of
"HardDisk:Users:Bill:Desktop:".
end if
if (test = 5) then -- THIS WORKED PERFECT
tell application "Finder"
set folder_ref to (choose folder)
open folder folder_ref
-- (TYPO "set Sel" should be "set aSel") set Sel to get
((every document file of (every folder of folder_ref)) whose (name
extension is "txt")) as alias list
tell application "Finder" to set aSel to (get (every document
file of (every folder) of folder_ref) whose name extension is "txt")
& (get (every document file of folder_ref) whose name extension is
"txt")
repeat with theItem in aSel
set the creator type of theItem to "R*ch"
end repeat
end tell
-- THIS WORKED PERFECT
end if
if (test = 6) then -- THIS WORKED PERFECT
tell application "Finder"
set folder_ref to (choose folder)
open folder folder_ref
-- (TYPO "set Sel" should be "set aSel") set Sel to get
((every document file of (every folder of folder_ref)) whose (name
extension is "txt")) as alias list
tell application "Finder" to set aSel to (get (every document
file of folder_ref) whose creator type is "MSIE") & (get (every
document file of (every folder) of folder_ref) whose creator type is
"MSIE")
repeat with theItem in aSel
set the creator type of theItem to "R*ch"
end repeat
end tell
-- THIS WORKED PERFECT
end if
-- Thanks again...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden