• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Follow-up: files in subfolders
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Follow-up: files in subfolders


  • Subject: Re: Follow-up: files in subfolders
  • From: kai <email@hidden>
  • Date: Mon, 13 Oct 2003 04:59:37 +0100

on Sun, 12 Oct 2003 08:50:59 -0500, Craig Sutherland wrote:

> Terry.
>
> set _folder to choose folder
> set _fileList to {}
>
> tell application "Finder"
> set _list to every file of _folder as alias list
> end tell
>
> repeat with _file in _list
> set _info to info for _file
> set _name to name of _info
> set _fileList to _fileList & _name
> end repeat
> _fileList

Actually, you should be able to get similar results with something like:

-------------------------

tell application "Finder" to set l to name of ((choose folder)'s files)

-------------------------

However, this doesn't drill down through nested folders (as 'entire
contents' does) or filter out unwanted files.

To do this in OS 9, you could get away with:

[one line]
-------------------------

tell application "Finder" to set l to name of files in (choose folder)'s
entire contents whose file type is "TEXT"

-------------------------

...but if no files are found in OS X, this could error - so you may need
something more like:

[rejoin line 2]
-------------------------

tell application "Finder" to try
set l to name of files in (choose folder)'s entire contents whose file
type is "TEXT"
on error
set l to {}
end try
l

-------------------------

> On Oct 11, 2003, at 9:25 PM, Terry Hill wrote:
>> I was trying out your suggestion that was posted on the AppleScript
>> digest, and got it to work for a similar problem I was having. I do
>> have one follow-up question if I may ask you ...
>>
>> My script below, asks the user for a folder to search, then searches
>> for all of the files ending in the suffix ".tex".
>> Per your code, it returns the list, but in the following verbage:
>> "{document file "Hill_aareuntion.tex" of folder "Hill" of folder
>> "Report Project" of folder "All Reports" of startup disk, document file
>> ...."
>>
>> How can I get it to return the list of the files, searching through
>> sub-folders, returning the path to the file, such as: HD:All
>> Reports:Report Project:Hill:Hill_aareuntion.tex ?
>>
>> You Wrote:
>> Date: Fri, 10 Oct 2003 09:24:19 -0500
>> Subject: files in subfolders (was Re: file type question)
>> From: John Adam Bloom <email@hidden>
>> To: email@hidden
>>
>> 'Tis simple: get every file IN ENTIRE CONTENTS OF folder "HD1:Misc:"
>> whose file type = "TEXT"

If you wanted a list of file paths rather than filenames, you might try
something along these lines, which should work in both OS 9 and OS X:

[rejoin line 4]
-------------------------

set f to choose folder
set text item delimiters to ASCII character 1
tell application "Finder" to try
set l to text items of ((files in f's entire contents whose file type is
"TEXT") as string)
if l is {""} then error
on error
set l to {}
end try
set text item delimiters to {""}
l

-------------------------

One more thing. If you're really looking for files with a specific name
extension, such as "tex", then try this instead:

[rejoin line 3]
-------------------------

set f to choose folder
set text item delimiters to ASCII character 1
tell application "Finder" to set l to text items of ((files in f's entire
contents whose name extension is "tex") as string)
set text item delimiters to {""}
if l is {""} then set l to {}
-- do something with l

-------------------------

---
kai
_______________________________________________
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.

  • Prev by Date: How do I get the IP address of an interface via applescript?
  • Next by Date: good book about applescript on os x?
  • Previous by thread: Re: How do I get the IP address of an interface via applescript?
  • Next by thread: good book about applescript on os x?
  • Index(es):
    • Date
    • Thread