File extension added to f = io.open ()

I am having problems with the log file name. As soon as you name it, I want the code itself to be deleted by extension .txt, but how can I do this? I use this to name it:

LogName = io.read()
f=io.open(LogName, "w")

I tried to make a f=io.open(LogName,".txt","w")whole bunch of others.

+4
source share
1 answer

Try string concatenation with the ..double period operator .

f=io.open(LogName .. ".txt", "w")

However, you can check if the extension exists at the end LogName, with something like this.

if LogName:lower():find'%.txt$' then
    -- ...
end
+5
source

All Articles