ScriptSpot

Forum topic · General Scripting

SaveText to File

By JokerMartini · 2010-12-06

Description

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 (1)

Swordslayer · 2010-12-07

Just replace

substring SaveLocation 1 (SaveLocation.count-4)

with

substring SaveLocation (SaveLocation.count-3) SaveLocation.count

and it should be all ok.