Notifications
Clear all

[Closed] Checking free disk space from maxscript

Hello,

I would like to check the free disk space (on the render server) before sending a netrender job from maxscript. SpaceOnDisk should do what I need, but it only supports the working disk (“Currently, this only returns correct results for one disk, your workdisk (given by .workdisk)”).

I can’t find a similar function in dotnet either.

Any suggestions?

6 Replies
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

(
	drives = (dotnetclass "System.IO.DriveInfo").GetDrives()
	for d in drives do
	(
		format "Name: %
" d.Name
		if d.IsReady then
		(
			format "	Available free space: % bytes
" d.AvailableFreeSpace
			format "	Total available space: % bytes
" d.TotalFreeSpace
			format "	Total size of drive: % bytes
" d.TotalSize
		)
		else 
		(
			format "	The device is not ready.
"
		)
	)
)

Have you seen my post here?

http://forums.cgsociety.org/showpost.php?p=5894457&postcount=9

Or you download my KClasses and do something like this

Code:
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!

Denis, that would only work on mapped drives, right?

BTW, if you want more info here’s this link:

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

Kameleon is right. My solution is just for mapped drives.
let’s ask c# for some help:


 global DriveAssembly
 fn CreateDriveAssembly forceRecompile:on =
 (
 	if forceRecompile or not iskindof ::DriveAssembly dotnetobject or (::DriveAssembly.GetType()).name != "Assembly" do
 	(
 
 source = ""
 source += "using System;
"
 source += "using System.Runtime.InteropServices;
"
 source += "public class DriveOps
"
 source += "{
"
 source += "	[DllImport(\"kernel32.dll\", CharSet = CharSet.Auto, SetLastError = true)]
"
 source += "	internal static extern bool GetDiskFreeSpaceEx(
"
 source += "		string directoryName, 
"
 source += "		out long freeBytesAvailable, 
"
 source += "		out long totalNumberOfBytes, 
"
 source += "		out long totalNumberOfFreeBytes);
"
 source += "	public static long[] GetDiskInfo(string directoryName)
"
 source += "	{
"
 source += "		long freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes;
"
 source += "		try { GetDiskFreeSpaceEx(directoryName, out freeBytesAvailable, out totalNumberOfBytes, out totalNumberOfFreeBytes); }
"
 source += "		finally { };
"
 source += "		return (new long[] { freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes });
"
 source += "	}
"
 source += "}
"
 
 		csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
 		compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
 
 		compilerParams.ReferencedAssemblies.Add("System.dll");
 
 		compilerParams.GenerateInMemory = true
 		compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
 		DriveAssembly = compilerResults.CompiledAssembly
 	)
 )
 
 -------------------------------------------------------------------------
CreateDriveAssembly forceRecompile:on

 global getDriveSpace = (DriveAssembly.CreateInstance "DriveOps").GetDiskInfo
 getDriveSpace "c:"
 

probably it’s exactly the same as Kameleon does do. So give him the credit

Yeah, that’s what I have on my custom dll, I never got that maxscript assemblies thingy you do… since I need to try, error, see VB messages for what I did wrong, try, error, etc etc Oh and I dont mind dividing the props with the Uber DenisT It’s an honor hehe

That’s just brilliant guys, many thanks.

I’ve tested it with

getDriveSpace @"[\\Computername\Render\](file://ComputernameRender)"

and that works great.

(Sorry for the late response)