Re: Index a given folder
Re: Index a given folder
- Subject: Re: Index a given folder
- From: Thomas Fischer <email@hidden>
- Date: Thu, 8 Apr 2010 21:38:45 +0200
Hi Jason,
since you insist:
You might try
property fileName : "File List.txt"
on run
set folderList to choose folder with prompt "Get list of files from this folder:" with multiple selections allowed # produces a list
open the result
end run
on open droppedItems
set ASTID to AppleScript's text item delimiters
# tell application "Finder" to launch # not needed
set AppleScript's text item delimiters to return
repeat with thisItem in droppedItems
if (folder of (info for thisItem without size)) is true then
tell application "Finder" to set fileList to the name of every item of entire contents of thisItem as text # reduces to name only
try
set fileName to ((thisItem as text) & fileName)
set eof file fileName to 0
write fileList to file fileName
on error errorMsg number errorNum
display dialog "Error (" & errorNum & "):" & return & return & errorMsg with icon caution
end try
end if
end repeat
set AppleScript's text item delimiters to ASTID
return true
end open
If you want more of a challenge, you might try to find out the different possibilities to do this using "System Events" and the reason why it takes ages to do that…
I wasn't aware of the "entire contents" property and am amazed that it actually looks into the contained folders, thanks for that!
By the way, this method deletes the contents of "File List.txt" first, otherwise there might be rests of earlier contents at the end.
You can try to sort the list using Finder, but again this is very slow. You can, however, sort the list using satimage osax:
tell application "Finder" to set fileList to (the name of every item of entire contents of thisItem) #as text
set fileList to (sortlist fileList) as text
Cheers
Thomas
Am 08.04.2010 um 09:28 schrieb Jason Donnelly:
> 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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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