get names of files in a folder

hi!
i try to write a script wich gives me the names of the files in a folder, one after the other.

i thought of a script like that:

set a to choose folder as alias
tell application “Finder”
set b to “”
repeat with c in a
set d to name of c
set b to b & " " & d
end repeat
end tell

but it doesn’t work…

… hope you can help me!

nicki


tell application "Finder"
	set theFolder to folder "Path:To:The:Folder:"
	get name of files of theFolder
end tell

or if the the folder has files and subfolders your could use:


get name of entire contents of theFolder

both of these will return you an alphabetical list.

and how can paste the names to TextEdit?
tell application “Finder”
set theFolder to folder “Book:Users:myusername:Music:Mymusic”
set c to the name of folders of theFolder
end tell
tell application “TextEdit” to activate

– how to paste c to TextEdit?

Thanx 4 helping

Regards Gergo, from Romania.:slight_smile:

Model: PowerBook
Browser: Firefox 2.0.0.12
Operating System: Mac OS X (10.4)

Hi Gergo,

something like this


tell application "Finder"
	set theFolder to folder ((path to music folder as text) & "Mymusic:")
	set c to the name of folders of theFolder
end tell
set {TID, text item delimiters} to {text item delimiters, return}
set c to c as text -- flatten the list with carriage returns
set text item delimiters to TID

tell application "TextEdit"
	activate
	set text of document 1 to c
end tell

As i read this topic i understand it as getting the files and not the files as in the script above

you might wanna change


set c to the name of folder of theFolder

to


set c to the name of files of theFolder

which only lists the files and not the folders…

And if I have a saved Text whit the names, how can I “update” it, don’t wanna clear the names at the document, just put the names on. Thank You for helping!