Advertisement
keebz

Get Random Files in Directory

Feb 17th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. strComputer = "."
  2.  
  3. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  4.  
  5. Set colFiles = objWMIService.ExecQuery _
  6.     ("ASSOCIATORS OF {Win32_Directory.Name='C:\temp'} Where " _
  7.         & "ResultClass = CIM_DataFile")
  8.  
  9. intFiles = colFiles.Count
  10.  
  11. Set objDictionary = CreateObject("Scripting.Dictionary")
  12.  
  13. intHighNumber = intFiles
  14. intLowNumber = 1
  15.  
  16. For i = 1 to 10
  17.     x = 0
  18.     Do Until x = 1
  19.         Randomize
  20.         intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
  21.         If objDictionary.Exists(intNumber) Then
  22.             x = 0
  23.         Else
  24.             objDictionary.Add intNumber, intNumber
  25.             x = 1
  26.         End If
  27.     Loop
  28. Next
  29.  
  30. i = 1
  31.  
  32. For Each objFile in colFiles
  33.     If objDictionary.Exists(i) Then
  34.         Wscript.Echo objFile.Name
  35.     End If
  36.     i = i + 1
  37. Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement