lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Thanks for your reply.

Actually, os.tmpname() creates a file with that name. So, in that case if I try to create the directory i.e., os.tmpname() as the file already exists with the same name of file, I think ubuntu mkdir command works.

Probably after calling os.tmpname(), we may have to call os.remove to delete the created file and we may have to create the directory. But is it really a reliable solution?


On Tue, Apr 21, 2015 at 9:03 PM, 书呆彭 <> wrote:
在 2015/4/22 10:01, Sravan Kumar Reddy Javaji 写道:
Hello Everyone,

As per the requirement, I want to create a temporary file with extension.

I know that os.tmpname create a temporary file, but there is no way to provide extension to it.

Could someone please let me know how to provide extension to the temporary file name.

Thanks for your help.


when I use tmpname, I'm expecting a filename which is guaranteed to be unique and that I have
proper privilege to use that file. but I don't know any means to provide some kind of `template'
so that tmpname would give a filename in special format. One can concatenate the name returned by
tmpname with a special suffix, but in theory he lose the guarantees provided by tmpname.

if I want create temporary files with special names, I would usually simply do:

local dirname = os.tmpname()
local myfile = .. "/file-with-special-name.specialsuffix", "wb")
--[[ blahblah ]]

NOTE: on a windows platform, use ``os.getenv("TMP") .. os.tmpname()`` instead.

the nerdy Peng / 书呆彭 / Sent from Thunderbird