Sort by name creates an empty list

I am trying to write a file with the list of all files contained in a folder and its subfolders with each filepath in a separate line. With the following code i get an empty file. Any idea why? Thanks.


set oldDelim to AppleScript's text item delimiters -- store default
tell application "Finder" to set theFilesPaths to every file of entire contents of (choose folder) -- list the files in a folder and all its subfolders
set flCnt to count theFilesPaths -- see how many files there are
set myList to {} -- prepare an empty list to receive the filepath coerced to text
repeat with i from 1 to flCnt -- go through every file
	set thisPathRef to item i of theFilesPaths as text -- change the format to volume:folder:subfolder:filename
	set myList's end to thisPathRef -- build up MyList in lines
end repeat
display dialog myList as text -- perfect this is what I want to sort and then write to file
-- something is going wrong after this point
tell application "Finder" to set sortedList to (sort myList by name) -- sort myList into sortedList
set prfsFlNm to "logFile" -- name the file
set prfsPth to (path to desktop folder as text) & prfsFlNm as text -- point the file to the desktop
wrtFl(prfsPth, sortedList as text) -- write it
-- and I get an empty file.
set AppleScript's text item delimiters to oldDelim -- restore to default
on wrtFl(flPth, flTxt) -- write a file
	try
		set mwTxtFl to open for access flPth with write permission
		set eof mwTxtFl to 0
		write flTxt to mwTxtFl
		close access mwTxtFl
	on error
		close access flPth
	end try
end wrtFl


I fixed it!
I kept myList in its original format until after the sort and then converted each item to text.
I post it for discussion and more elegant solutions.


set oldDelim to AppleScript's text item delimiters -- store default
tell application "Finder" to set theFilesPaths to every file of entire contents of (choose folder) -- list the files in a folder and all its subfolders
set flCnt to count theFilesPaths -- see how many files there are
set myList to {} -- prepare an empty list to receive the filepath coerced to text
repeat with i from 1 to flCnt -- go through every file
	-- set thisPathRef to item i of theFilesPaths as text -- change the format to volume:folder:subfolder:filename
	set thisPathRef to item i of theFilesPaths -- first modification
	set myList's end to thisPathRef -- build up MyList in lines
end repeat
--display dialog myList as text -- perfect this is what I want to sort and then write to file
-- fix
tell application "Finder" to set myList to (sort myList by name) -- sort myList into itself
set textList to {}
repeat with i from 1 to count myList
	set textList's end to item i of myList as text -- covert each item to text here after sorting
end repeat
set prfsFlNm to "logFile" -- name the file
set prfsPth to (path to desktop folder as text) & prfsFlNm as text -- point the file to the desktop
wrtFl(prfsPth, textList as text) -- write it
set AppleScript's text item delimiters to oldDelim -- restore to default
on wrtFl(flPth, flTxt) -- write a file
	try
		set mwTxtFl to open for access flPth with write permission
		set eof mwTxtFl to 0
		write flTxt to mwTxtFl
		close access mwTxtFl
	on error
		close access flPth
	end try
end wrtFl