Placing find results to a list

Hey all,

I’ve been trying to make a script to do the following but i’m novice apple scripter.

using this script:

What I would like is the following:

  1. I would to find all files in a directory and subdirectory that contain the .txt file extension.
    a. Default directory would be ~/home/Desktop/Import
  2. The results would only contain the filename.
    search would yield

what i need only:

  1. If the result could be stored in a list
    ex. {“file”,“file2”}

thanks if anyone could shed some light in this


Here’s a quick one… all AS, no shell (not a shell scripter)…

set nameExtension to "jpg" -- Change this as needed
set fileList to {} -- Set up an empty list to populate
tell application "Finder" to set tempFileList to ((name of every file of folder "AI Math Scripts" of desktop) whose name extension is nameExtension) -- Change the "of folder "AI Math Scripts" of desktop" by droplet, selection, choose folder, whatever.
repeat with thisFileName in tempFileList
	set fileList to fileList & ((characters 1 through -((count of nameExtension) + 2) of thisFileName) as string) -- Subtract 2 to get beyond the dot prefix.
end repeat

Jim Neumann

Thanks for the reply. Could please tell me how you to modify the script to do the following:

  1. go to a specific directory. (ex. ~/docs/folder)
  2. Also search the sub directories?

thanks again…

Thank you for all the help greatly appreciated.

Special thanks:

A variation of Jacques’ script:

choose folder

do shell script "/usr/bin/find " & quoted form of POSIX path of result & " -name '*.txt' -exec /usr/bin/basename {} \\; | /usr/bin/sed s/.txt$//g"
return paragraphs of result