Write names of files to text file

I need to write a script that will write the name of each file in a folder to a text file. Anyone have one already?

Try this:

set f to choose folder
tell application "Finder"
	set fn to name of f
	set nameList to name of files of entire contents of f
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to return
	set nameList to nameList as text
	set AppleScript's text item delimiters to tid
end tell

set textFile to open for access ((path to desktop folder as text) & fn & " contents.txt") with write permission
	set eof of textFile to 0
	write nameList to textFile
	close access textFile
on error e
	close access textFile
	display dialog e
end try

It’s a one-liner from the terminal:

ls /path/to/folder > /path/to/textfile

The resulting file is UTF8-encoded.


Wow that’s great. I really appreciate it!