Este Script te permite buscar un archivo y te muestra sus detalles. Es un buen ejemplo ya que te ayuda a empezar a usar algunas funciones de manipulación de archivos, ventanas y ciclos.

FileInfo.vbs

Visual Basic:
  1. ' FileInfo.vbs  Quickly search your drive for specified file name and return
  2. ' path, version, size and date information.  Can search a specified drive, or
  3. ' or all drives.  Use only the file name, not the extension.  Requires WMI,
  4. ' which is included with Windows 2000 and Windows XP.  For Windows 95, 98, ME
  5. ' and NT4, WMI can be downloaded at
  6. ' http://msdn.microsoft.com/downloads/sdks/wmi/download.asp
  7. ' © Bill James - wgjames@mvps.org - Released 14 Nov 2002 - Revised 16 Nov 2002
  8.  
  9. Option Explicit
  10. Dim fso, OutFile, sDrv, sFName, sReport, sFile, sTitle
  11. sTitle = "FileInfo.vbs © Bill James"
  12. Set fso = CreateObject("Scripting.FileSystemObject")
  13. OutFile = "C:\searched.txt"
  14. If fso.FileExists(OutFile) Then fso.DeleteFile(OutFile)
  15. Set sReport = fso.OpenTextFile(OutFile, 8, True)
  16.  
  17. sDrv = InputBox("Enter drive letter to search (letter only)" & vbcrlf & _
  18.                 vbcrlf & "(Enter * to search all local drive letters)", sTitle)
  19. If sDrv = "" Then WScript.Quit
  20. sFName = InputBox ("Enter file name to search for (no extension)", sTitle)
  21. If sFName = "" Then WScript.Quit
  22.  
  23. GetResults "c:", sFName
  24.  
  25. sReport.Close
  26. Set sReport = Nothing
  27.  
  28. Dim f, ra, Results
  29. Set f = fso.OpenTextFile(OutFile)
  30. On Error Resume Next
  31. ra =  f.ReadAll
  32. If Err Then
  33.   Results = 0
  34. End If
  35. On Error GoTo 0
  36.  
  37. f.Close
  38. Set f = Nothing
  39. Set fso = Nothing
  40.  
  41. If Results> 0 Then
  42.   Wscript.CreateObject("WScript.Shell").Run OutFile
  43. Else
  44.   MsgBox "No matches found for " & chr(34) & sFName & chr(34) & " on " & sDrv,, sTitle
  45. End If
  46.  
  47. Sub GetResults(drv, fname)
  48.   Dim sWQL, oFile, sAttrib
  49.   sWQL = "select * from cim_datafile where Drive='" & _
  50.          drv & "' AND FileName = '" & fname & "'"
  51.   For Each oFile In GetObject("winmgmts:").execquery(sWQL)
  52.     Results = Results + 1
  53.     sFile = oFile.Name
  54.     Set f = fso.GetFile(sFile)
  55.     sReport.WriteLine sFile & vbcrlf & "Version: " & _
  56.       fso.GetFileVersion(sFile) & vbcrlf & "Created: " & _
  57.       f.DateCreated & vbcrlf & "Modified: " & f.DateLastModified & _
  58.       vbcrlf & "Size: " & FormatNumber(f.Size, 0) & " bytes"
  59.     If oFile.Archive Then sAttrib = "Archive "
  60.     If oFile.Compressed Then sAttrib = sAttrib & "Compressed "
  61.     If oFile.Encrypted Then sAttrib = sAttrib & "Encrypted "
  62.     If oFile.Hidden Then sAttrib = sAttrib & "Hidden "
  63.     If oFile.System Then sAttrib = sAttrib & "System "
  64.     If NOT oFile.Writeable Then sAttrib = sAttrib & "ReadOnly "
  65.     If sAttrib <> "" Then sReport.WriteLine "Attributes: " & sAttrib & vbcrlf
  66.     sAttrib = ""
  67.   Next
  68. End Sub
  69.  
  70. ' Revisions
  71. '   15 Nov 2002 - Added MsgBox if no search matches found.
  72. '   16 Nov 2002 - Added file attributes to the report

Popularidad: 22%