Retrieve Username

I am trying to detect the existence of file

function find_host_dbx(file_name)
  local, "r") 
  if host_dbx_found==nil then
     host_dbx_found=file_name .. " ... Error - File Not Found"
     host_dbx_found=file_name .. " ... File Found"
  return host_dbx_found

it seem I can’t do it like that.

can someone help me please

when I replace %username% by the computer user’s name it works

The environment variable substitution isn’t built into the file library. You should be able to use os.getenv() to search for the value, say by adapting the manual’s example here (from "%$(%w+)" to something like %%(%w+)%%", probably).

I think it should be something like this

local filePath = system.pathForFile( "your_file_here", system.DocumentsDirectory ) -- it might be in another location than system.DocumentsDirectory
local file = filePath, "r" )
if file then
  --file found
--file not found
io.close( file )

this link might help a bit

And if your files are located outside the reach of Solar2D code capabilities then you should use a plugin for that

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.