It would return the value set in the configs for max storage size, as, as for as I know, there is no way currently to obtain this value other than getting the file size of every file on the drive.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Function in fs API to get Max Drive Space
Started by Selim, 18 May 2016 - 05:28 PMPosted 18 May 2016 - 07:28 PM
Simple, just a function in the fs API labeled something like "fs.getMaxSpace" that takes one argument that is a path string. This allows the function to know what file system it is checking, whether it is the computers drive, floppy disk, PC in a disk drive, etc. Works similarly to "fs.getFreeSpace".
It would return the value set in the configs for max storage size, as, as for as I know, there is no way currently to obtain this value other than getting the file size of every file on the drive.
It would return the value set in the configs for max storage size, as, as for as I know, there is no way currently to obtain this value other than getting the file size of every file on the drive.
Edited on 18 May 2016 - 05:29 PM
Posted 19 May 2016 - 06:27 AM
Would be useful. Nobody wants to get the total size of all files on the drive and then add it to the amount of free space
Posted 22 May 2016 - 09:19 AM
This is kinda senseless. Afaik you can do this:
local max = fs.getSize("/disk") + fs.getFreeSpace("/disk")
Posted 22 May 2016 - 04:09 PM
I tried that with the root filesystem, and it didn't seem to get the size of folders properly, returned zero. I may have done something dumb, but that is what I got. So, I would think a solution that doesn't depend on fs.getSize would be nice.–snip–
Edited on 22 May 2016 - 05:57 PM
Posted 22 May 2016 - 10:23 PM
Posted 23 May 2016 - 03:18 PM
I know this is a possibility, but I didn't really want to have to loop though each folder.
Posted 23 May 2016 - 06:24 PM
That's pretty much the only way though. You're going to have to loop through each folder regardless. Now, more than likely Dan could easily code up a java implementation in which it just returns the number specified in the config file, but if you want to do it on your own, you HAVE to recursively loop through each folder.
Posted 23 May 2016 - 07:26 PM
I know that if I did it Lua-side, I would have to loop through, and that is why this is in the "Suggestions" subforum rather than "Ask a Pro". I was hoping that Dan would add a Java-side function.–snip–
Posted 24 May 2016 - 03:41 PM
I'm meaning in ANY language you have to loop. C#, C++, Java. You have to loop to get the full size of a directory and any sub directories. I know that C# has a shortcut, however that only works if you're absolutely sure that each and every file/folder can be read / size can be gained.
Now as I said, Dan could just return the already made config file size.
http://pastebin.com/9ery1NPb
Nice little example for c# that I had to do as my assignment.
Now as I said, Dan could just return the already made config file size.
http://pastebin.com/9ery1NPb
Nice little example for c# that I had to do as my assignment.
Edited on 24 May 2016 - 01:47 PM
Posted 24 May 2016 - 04:20 PM
I understand what you are saying, I just want a function that will not consume as much memory as a recursive loop by just returning the config value.–snip–
Posted 24 May 2016 - 04:29 PM
Well yeah, that's entirely possible, but as I've said on each of my posts he could do that easily, but that is the only situation anywhere in which you can return that size without a loop.