SaveText to File

When I evaluate this script and hit save then type in "Cool" it saves the file correctly as "Cool.txt" but when I typed in "Cool.txt" it saves the file as "Cool.txt.txt"

Not sure where its bugging out here. Let me know if anyone has the solution.
Thank you.

	fn saveTaskList SaveLocation =
	(
		if (substring SaveLocation 1 (SaveLocation.count-4))==".txt" then
			(
				TaskList = createFile SaveLocation
			)
			else 
			(
				TaskList = createFile (SaveLocation+ ".txt")
			)
		format "Hi" to:TaskList
	)
 
rollout rlSaveText "Save Text"
(
	local SaveLocation = undefined
 
	button btnSave "Save"
 
on btnSave pressed do
	(
		SaveLocation = getSaveFileName caption:"Save Task List" types:"Text Documents(*.txt)|All|All Files(*.*)|"
		if SaveLocation != undefined then
		(
			saveTaskList SaveLocation
		)
	)
)
createDialog rlSaveText 150 150

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Swordslayer's picture

Just replace substring

Just replace substring SaveLocation 1 (SaveLocation.count-4) with substring SaveLocation (SaveLocation.count-3) SaveLocation.count and it should be all ok.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.