Folder listing question

Hello People…

I’m using this to list a folder of items, and would like to show if it is a folder or a file, the name and “type”
is added to a tableview… but I got a few problems…

The folder contains 3 files and 1 folder
file1.txt, file2.txt, file3.txt and folder Hello


tell application "Finder"
	set theFolder to choose folder with prompt "Select a folder"
	set theFiles to every file of theFolder
	set myTableListOfLists to {}
	repeat with a in theFiles
		set theFile to file ((item a of theFiles) as string)
		set fileName to the name of theFile
		set fileKind to the kind of theFile
	end repeat
	set end of myTableListOfLists to {fileName, fileKind}
end tell

But it only outputs this line.
–{“Hello”, “Folder”}

I’m pretty sure it’s just something simple I missed but I can’t see what…

Would somebody be so kind to kick me in the right direction…

Thanks…

Hi,

myTableListOfLists is set only once outside the repeat loop
and your repeat loop form cannot work at all

either

repeat with a in something
	a as string
end repeat

or


repeat with a from 1 to count something
	item a of something as string
end repeat

optimized version of the script


set theFolder to choose folder with prompt "Select a folder"
tell application "Finder" to set theFiles to every file of theFolder
set myTableListOfLists to {}
repeat with a in theFiles
	tell a to set end of myTableListOfLists to {name, kind}
end repeat


Hi Stefan, I see what you mean, I was wrong on setting the myTableListOfLists
I changed " every file " to " every item " to get folders to, but still I only get 1
result back…

In addition to what StefanK has noted, you aren’t getting the folder names. Then at the end of the script, you only see the last item added.

tell application "Finder"
	set theFolder to choose folder with prompt "Select a folder"
	set theFiles to every file of theFolder
	set thefolders to every folder of theFolder
	set myTableListOfLists to {}
	repeat with a in theFiles
		set theFile to name of a as string
		set fileKind to the kind of a
		set end of myTableListOfLists to {theFile, fileKind}
	end repeat
	repeat with a in thefolders
		set theFile to name of a as string
		set fileKind to the kind of a
		set end of myTableListOfLists to {theFile, fileKind}
	end repeat
	set x to count of myTableListOfLists
	display dialog myTableListOfLists as string
	display dialog x
end tell

Note that this does not drill down through folders. Any files/folders within folders are not counted. It only shows all files and folders at the top level, and the display isn’t formatted. It’s just so you can see that they’re there. The variable x tells you how many files/folders it found.

of course, the result is the value of the last statement (set end of.)
if you recall the variable myTableListOfLists, you get the whole list


set theFolder to choose folder with prompt "Select a folder"
tell application "Finder" to set theFiles to items of theFolder
set myTableListOfLists to {}
repeat with a in theFiles
	tell a to set end of myTableListOfLists to {name, kind}
end repeat
myTableListOfLists

Man, how can something so simple be so hard, I feel so stupid right now. A big thanks to both of you…
I think I got a hang of it now…