Jump to content
  • 0

How to check if a file exist at a directory?


RevealedSoulEven

Question

I'm creating a password session that is automatically saved in the internal storage. So that the users don't have to put it again.

Once it's created I can check the password. I did that.

But the thing is if the file doesn't existed there then how to verify? If the file is present in the storage or not?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

Just now, CmP said:

function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end

Source: https://stackoverflow.com/a/499160

Thank you for your help sir... But I've already saw that on stackoverflow and it's not working with GG. Because it doesn't return nil instead it returns something else. Randomly so.. we can't

Link to comment
Share on other sites

1 minute ago, RevealedSoulEven said:

Because it doesn't return nil instead it returns something else. Randomly so.. we can't

Provide an example of what "io.open" function returns for existing file and non-existing one. You can use the following code for this: 

local path = "/path/to/a/file"
print(io.open(path, "r"))
Link to comment
Share on other sites

2 minutes ago, CmP said:

Provide an example of what "io.open" function returns for existing file and non-existing one. You can use the following code for this: 


local path = "/path/to/a/file"
print(io.open(path, "r"))

Thank you sir I'll try

[added 2 minutes later]
4 minutes ago, CmP said:

Provide an example of what "io.open" function returns for existing file and non-existing one. You can use the following code for this: 


local path = "/path/to/a/file"
print(io.open(path, "r"))

Yes sir that's working. Thank you

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.