Get list of files in folder without using choose folder

I can’t seem to make this work. I just use applescript for very basic things and I can’t get this to work the way I want.
This script will work with choose folder but it won’t work if I try to specify a specific folder.

tell application “Finder”
activate
set the_folder to (choose folder)

		select (every file in folder the_folder)
		
		
		set the_list to the name of every file in the_folder
		
	end tell
	tell application "Finder"
		activate
		
		if the_list is not {} then
			activate
			set pickfile to ¬
				choose from list the_list with prompt ¬
					"Choose which note file to add to:" OK button name ¬
					"choose" cancel button name "Name a new notefile" default items {item 1 of the_list} empty selection allowed true ¬
					with multiple selections allowed 

end if
end tell

If I try to replace (choose folder) with a specific path
like: set the_folder to “macintosh HD:users:admin:documents:KNoteTaker”
or to set the_folder to (path to documents folder) & “KNoteTaker”

it doesn’t work.

Can anyone tell me how to specify a path to a folder that will get the names of files in that folder into a list.
Thanks

On a separate script, just run choose folder. The result (in the result pane at the bottom) will be the required path to the folder you want. Copy it and paste it into the one you are working on.

Thanks for the reply but getting the correct path isn’t the problem.
The script works with choose folder but breaks if I specify the path.

it either hits a problem at this line:
set the_list to the name of every file in the_folder

or when it trys to display the_list as a choice.

What I am trying to do is take a selection from Safari and pick a text file from the files in a specific folder and append the selection to the end of the text file using textedit. The code is where I have a problem. Everything works if I use choose folder but breaks when I try to specify a path and I don’t know enough to tell why.

I don’t want to always have to specify the path.

Is this what you’re looking for?

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Yes, thank you
your script is cleaner but just to see if I could, adding the “as unicode text” in the path to documents folder statement made my script work too.

Thanks again