Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Free space check but exclude C D or other drive 2

Status
Not open for further replies.

DvZ73

IS-IT--Management
Nov 3, 2013
16
NL
I'm creating a script that creates a folder and copy's data to a share on the server

First i check wich disk has the most free space
then i create the folder and share on that drive with most free space

No i have the following problem , i have 8 drives C, D, E, F, G, H, I, J
The script checks only for disk with most free space
Now the folder got created on C an D And J wich are the drives with the most free space
but aren't allowed to be used.
How to i exclude the drives from checking for free space ?
the script for free space checking is:
Code:
strserver = "dafwesmfs1"

mostFree = 0

set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strserver & "\root\cimv2")

' Drive Type 3 is for Hard Disk
Set objDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = 3")

' Enumerate Each Drive
For Each objDisk in objDisks
numFreeSpace = objDisk.FreeSpace
  If mostFree > 0 Then
      If mostFree  - objDisk.FreeSpace < 1 Then
          mostFree = objDisk.FreeSpace
          mostFreeDrive = objDisk.DeviceID
      End If
  ElseIf objDisk.FreeSpace > 0 Then
      mostFree = objDisk.FreeSpace
     mostFreeDrive = objDisk.DeviceID
  End If

next

letter=Mid(mostFreeDrive, 1, 1)

wscript.echo "drive letter is: " & letter

How do i acomplish this ?
thx for reading my question
 
If you just want to hard code the skipping of those drive letters, then this should work:
Code:
For Each objDisk in objDisks
   If objDisk.DeviceID <> "C:" And _
      objDisk.DeviceID <> "D:" And _
      objDisk.DeviceID <> "J:" Then

      . . .

   End If
next
 
I think I'd be tempted to modify the WQL instead:

[tt]("Select * from Win32_LogicalDisk Where DriveType = 3 [blue]And DeviceID Like '[^CDJ]:'[/blue]")[/tt]​
 
Thank you both for the help,
guitarzan, that would be mine solution if i tought of that now i saw i tought yeah right.
but going for the solution of Strongm ofcourse :)

thx guy's
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top