Notifications
Clear all

[Closed] DotNetClass [System.IO.DriveInfo]

Can someone give me some pointers with regard how to get the following DotNetObject/Class to check if the renderoutput location defined by an artist is attempting to save the output to a file server which has a threshold of say < 5GB in “available free space”.

So far I have:

x = DotNetClass "System.IO.DriveInfo"
RenderOutput = outputfilename

“AvailableFreeSpace” is the method on MSDN.

Mike

14 Replies

hi mike

try


SomeDriveInfo = DotNetobject "System.IO.DriveInfo" "c:\\"
-- result is in bytes so divide a few times to get GB
GBleft = (((SomeDriveInfo.AvailableFreeSpace/1024)/1024)/1024)
if GBleft > 5 then print "enough space" else print "medic!"

Thanks Pete, much appreciated!
However, a problem, which I can’t think of a workaround is, if the path is a UNC path, then it doesn’t work!

All these are vaild…

DriveOutput = DotNetobject "System.IO.DriveInfo" "C"
DriveOutput = DotNetobject "System.IO.DriveInfo" "C:"
DriveOutput = DotNetobject "System.IO.DriveInfo" "C:\\"

But,

DriveOutput = DotNetobject "System.IO.DriveInfo" "\\myserver\\"

fails

Mike

According to the error (“– Runtime error: dotNet runtime exception: Object must be a root directory (“C:”) or a drive letter (“C”).”) you must point to a drive letter, so unmapped unc paths will be invalid.

-Eric

hi mike, could you map a network path and use that letter instead?

Hence my problem…!
Looks like a lookup table for UNC paths against drive letters is the only option

or some more storage!

Have a look at this : http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/63c0b94a-8e53-46f8-b46e-c2e8c9f4686f

You can write a custom class and you’ve solved your problem. Cheers

Or you download my KClasses and do something like this

dotnet.loadassembly @"C:\KClasses.dll"
		
dnGet=dotnetObject "KClasses.DnGetDiskFreeSpaceEx"
dnGet.dnGetDiskFreeSpace @"\\yourserver\shared\"
print (((dnGet.freeBytes / 1024) / 1024) / 1024)

Values are returned in Long. Cheers!

Thanks very much Kameleon, much appreciated.
However, running this code;

dotnet.loadassembly @"C:\KClasses.dll"
dnGet=dotnetObject "KClasses.DnGetDiskFreeSpaceEx"
dnGet.dnGetDiskFreeSpace @"\\myserver"
GBleft = (((dnGet.freeBytes/1024)/1024)/1024)

results in:

dotNetObject:System.Reflection.Assembly
dotNetObject:KClasses.dnGetDiskFreeSpaceEx
false
0L

But myserver has 7GB free…! Does this class work on a x64bit XP OS with x64bit Max?

BTW, what did you use to compile the dll with? VS2008 Express?

Thanks,

Mike

Page 1 / 2