Re: Index a given folder
Re: Index a given folder
- Subject: Re: Index a given folder
- From: Jason Donnelly <email@hidden>
- Date: Thu, 8 Apr 2010 00:28:29 -0700
These have been very useful -- thanks. Using them as a basis, and with
a little help from a friend (the Internet!), we came up with this,
which lists files located in sub-folders as well, but which
unfortunately records the full file path in every case (e.g.,
Macintosh HD:Users:jwdonnel:Documents:example.pdf). Can't really take
full credit for this, but getting closer.
Thanks also for the TextWrangler tip, that actually does pretty much
exactly what I want -- but, can't shy away from a challenge, no fun in
that at all.
Here's the script:
property fileName : "File List.txt"
on run
choose folder with prompt "Get list of files from this folder:"
open {result}
end run
on open droppedItems
set ASTID to AppleScript's text item delimiters
tell application "Finder" to launch
repeat with thisItem in droppedItems
if (folder of (info for thisItem without size)) is true then
set AppleScript's text item delimiters to (ASCII character 13)
tell application "Finder" to set theList to entire contents of
thisItem as text
set AppleScript's text item delimiters to ""
try
open for access file ((thisItem as text) & fileName) with write
permission
set theFileRef to result
write theList to theFileRef
close access theFileRef
on error errorMsg number errorNum
try
close access theFileRef
end try
display dialog "Error (" & errorNum & "):" & return & return &
errorMsg buttons "OK" default button 1 with icon caution
end try
end if
end repeat
set AppleScript's text item delimiters to ASTID
return true
end open
As I said, seems to work, for the most part -- but, it produces the
text index file in the folder chosen for indexing; also, the full file
path problem.
Thanks again -- Jason.
On 7-Apr-10, at 4:47 PM, Stockly, Ed wrote:
1. be pointed to a chosen folder,
2. will get the names of every file in that folder,
3. generate a text file which lists all the files in that folder
(order doesn't really matter, but alphabetical would be nice), and
4. save the text file to Desktop.
Try this:
HTH
ES
set myFolder to choose folder
open {myFolder}
on open folderList
repeat with thisFolder in folderList
set folderPath to thisFolder as text
if the last character of folderPath is ":" then
tell application "System Events"
set folderName to name of thisFolder
set fileName to "item names from " & folderName &
".txt"
set newFile to folderPath & fileName
set itemNames to the name of every item of thisFolder
as
list
end tell
set AppleScript's text item delimiters to {return}
set fileText to itemNames as text
my OpenWriteClose(newFile, fileText)
end if
end repeat
end open
on OpenWriteClose(myFile, myText)
try
set openFile to (open for access myFile with write permission)
on error
close access openFile
set openFile to (open for access myFile with write permission)
end try
set eof of openFile to 0
write myText to openFile
close access openFile
end OpenWriteClose
_______________________________________________
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/archives/applescript-users
This email sent to email@hidden