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

[LUA] disk.hasData("right") returns true on brand new floppy

Started by Ajax2422, 22 April 2012 - 04:50 AM
Ajax2422 #1
Posted 22 April 2012 - 06:50 AM
Using TMI to generate a brand new floppy, putting it into a drive, then using disk.hasData("right") returns true. How would I get it to return false? I've checked the %APPDATA%/.minecraft/saves/test/disk/15 folder, and it's empty (as expected), and disk.getLabel("right") returns null.
Luanub #2
Posted 22 April 2012 - 07:39 AM
Try making one without using TMI and see if it has the same problem. It's probably an issue with the TMI crafted item.
MysticT #3
Posted 22 April 2012 - 03:33 PM
I don't think that's what the function is made for. It returns true if there's a floppy disk on the drive, not if it has files on it. It would only return false if there's no disk or there's a music cd. To check if it has files you can do something like this:

function DiskHasData(side)
  if disk.isPresent(side) and disk.hasData(side) then
    local list = fs.list(disk.getMountPath(side))
    return #list ~= 0
  end
  return false
end
Ajax2422 #4
Posted 22 April 2012 - 04:27 PM
I don't think that's what the function is made for. It returns true if there's a floppy disk on the drive, not if it has files on it. It would only return false if there's no disk or there's a music cd. To check if it has files you can do something like this:

function DiskHasData(side)
  if disk.isPresent(side) and disk.hasData(side) then
    local list = fs.list(disk.getMountPath(side))
    return #list ~= 0
  end
  return false
end

Yes, that works perfectly. Thanks!
luniak #5
Posted 23 April 2012 - 11:03 AM
As far as i remember from diggout through code that method checks if there exist directory for inserted disk.
And folder for disk is created ehen you put it into disk drive :)/>/> so it returned allways true even for empty disks