This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
raxteeze's profile picture

We need a code that will find out whether there is a folder at least one file.

Started by raxteeze, 07 June 2015 - 09:51 AM
raxteeze #1
Posted 07 June 2015 - 11:51 AM
We need a code that will find out whether there is a folder at least one file.
theoriginalbit #2
Posted 07 June 2015 - 11:56 AM
We don't give out code. We like to see attempts at solving the problem and the issues you're facing so that we can help you with the code further. I suggest you take a look at the FS API.
raxteeze #3
Posted 07 June 2015 - 12:03 PM
We don't give out code. We like to see attempts at solving the problem and the issues you're facing so that we can help you with the code further. I suggest you take a look at the FS API.
I'm going to do with the function of the operating system on your computer desk. If a folder with accounts no file (account), the screen will display a license agreement and registration. If there is at least one file, it will display a login screen.

We don't give out code. We like to see attempts at solving the problem and the issues you're facing so that we can help you with the code further. I suggest you take a look at the FS API.
On FS API I looked. But nothing could be done.
Help me please.
Edited on 07 June 2015 - 10:08 AM
TheOddByte #4
Posted 07 June 2015 - 12:09 PM
- snip -
If it's only one file, and you know what file you're looking for you could use fs.exists.

local directory = "username"
local file          = "user.data"
if fs.exists( fs.combine( directory, file ) ) then
    --# The file existed
else
    --# The file was not in the folder
end
If it's just some random files and you just want to make sure the folder isn't empty you can use fs.list

local directory = "username"
local list           = fs.list( directory )
if #list > 0 then
    --# There are files in the folder
    --# But do note that this may not be the case
    --# because it may have found another empty
    --# folder in the folder and added it to the list
else
    --# The directory was empty
end
raxteeze #5
Posted 07 June 2015 - 12:12 PM
- snip -
If it's only one file, and you know what file you're looking for you could use fs.exists.

local directory = "username"
local file		  = "user.data"
if fs.exists( fs.combine( directory, file ) ) then
	--# The file existed
else
	--# The file was not in the folder
end
If it's just some random files and you just want to make sure the folder isn't empty you can use fs.list

local directory = "username"
local list		   = fs.list( directory )
if #list > 0 then
	--# There are files in the folder
	--# But do note that this may not be the case
	--# because it may have found another empty
	--# folder in the folder and added it to the list
else
	--# The directory was empty
end
Thank you =)