|
when I use tmpname, I'm expecting a filename which is guaranteed to be unique and that I have在 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.
-
Regards,
Sravan
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()
lfs.mkdir(dirname)
local myfile = io.open(dirname .. "/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