In VBScript, you can do this:
<% set fso = CreateObject("Scripting.FileSystemObject") for each drive in fso.Drives cDriveName = fso.GetDriveName(drive) set cDrive = fso.GetDrive(drive) if cDrive.DriveType=2 then response.Write cDriveName & " - " &_ formatnumber(cDrive.FreeSpace/1024/1024,0) &_ " MB free<br>" end if next set fso = nothing %> |
In JScript, you can do this:
<script language=jscript runat=server> var fso = new ActiveXObject("Scripting.FileSystemObject"); for (d = new Enumerator(fso.Drives); !d.atEnd(); d.moveNext()) { if (d.item().DriveType==2) { Response.Write(d.item() + " - "); var space = d.item().FreeSpace; space = Math.round(space/1024/1024); space = space.toLocaleString(); Response.Write(space.substring(0,space.length-3)); Response.Write(" MB free<br>"); } } var fso = null; </script> |
If you are concerned about the space on your SQL Server machine, you can do this:
| EXEC master..xp_fixedDrives |
Which will return a list like this:
drive MB free ----- ----------- C 2435 D 7596 E 6097 F 7892 G 7393 |
Note that this is an undocumented extended stored procedure, and should not be used in production code (since its behavior may change in future versions). Another alternative, for a single drive, is to parse the results of the following statement:
| EXEC master..xp_cmdshell 'dir c:\' |