Now, the code work very well, but I can’t convert the free space in MB
or any other unit, how can I convert it?
Thanks.
Best regards.
Hello Toki:
The drive.FreeSpace is being returned as a string (which may also be a
nil). Change #{drive.FreeSpace} to #{drive.FreeSpace.class} to see what
I mean. You’ll need to convert the FreeSpace to a number before you can
use math operators / functions with it. Below is an example of how to
do that with the #to_f (aka “to float”) method:
The drive.FreeSpace is being returned as a string (which may also be a
nil). Change #{drive.FreeSpace} to #{drive.FreeSpace.class} to see what
I mean. You’ll need to convert the FreeSpace to a number before you can
use math operators / functions with it. Below is an example of how to
do that with the #to_f (aka “to float”) method: