WSH: FileInfo Script
Posted on November 6th, 2007 in Código, Script |
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:
-
' FileInfo.vbs Quickly search your drive for specified file name and return
-
' path, version, size and date information. Can search a specified drive, or
-
' or all drives. Use only the file name, not the extension. Requires WMI,
-
' which is included with Windows 2000 and Windows XP. For Windows 95, 98, ME
-
' and NT4, WMI can be downloaded at
-
' http://msdn.microsoft.com/downloads/sdks/wmi/download.asp
-
' © Bill James - wgjames@mvps.org - Released 14 Nov 2002 - Revised 16 Nov 2002
-
-
Option Explicit
-
Dim fso, OutFile, sDrv, sFName, sReport, sFile, sTitle
-
sTitle = "FileInfo.vbs © Bill James"
-
Set fso = CreateObject("Scripting.FileSystemObject")
-
OutFile = "C:\searched.txt"
-
If fso.FileExists(OutFile) Then fso.DeleteFile(OutFile)
-
Set sReport = fso.OpenTextFile(OutFile, 8, True)
-
-
sDrv = InputBox("Enter drive letter to search (letter only)" & vbcrlf & _
-
vbcrlf & "(Enter * to search all local drive letters)", sTitle)
-
If sDrv = "" Then WScript.Quit
-
sFName = InputBox ("Enter file name to search for (no extension)", sTitle)
-
If sFName = "" Then WScript.Quit
-
-
GetResults "c:", sFName
-
-
sReport.Close
-
Set sReport = Nothing
-
-
Dim f, ra, Results
-
Set f = fso.OpenTextFile(OutFile)
-
On Error Resume Next
-
ra = f.ReadAll
-
If Err Then
-
Results = 0
-
End If
-
On Error GoTo 0
-
-
f.Close
-
Set f = Nothing
-
Set fso = Nothing
-
-
If Results> 0 Then
-
Wscript.CreateObject("WScript.Shell").Run OutFile
-
Else
-
MsgBox "No matches found for " & chr(34) & sFName & chr(34) & " on " & sDrv,, sTitle
-
End If
-
-
Sub GetResults(drv, fname)
-
Dim sWQL, oFile, sAttrib
-
sWQL = "select * from cim_datafile where Drive='" & _
-
drv & "' AND FileName = '" & fname & "'"
-
For Each oFile In GetObject("winmgmts:").execquery(sWQL)
-
Results = Results + 1
-
sFile = oFile.Name
-
Set f = fso.GetFile(sFile)
-
sReport.WriteLine sFile & vbcrlf & "Version: " & _
-
fso.GetFileVersion(sFile) & vbcrlf & "Created: " & _
-
f.DateCreated & vbcrlf & "Modified: " & f.DateLastModified & _
-
vbcrlf & "Size: " & FormatNumber(f.Size, 0) & " bytes"
-
If oFile.Archive Then sAttrib = "Archive "
-
If oFile.Compressed Then sAttrib = sAttrib & "Compressed "
-
If oFile.Encrypted Then sAttrib = sAttrib & "Encrypted "
-
If oFile.Hidden Then sAttrib = sAttrib & "Hidden "
-
If oFile.System Then sAttrib = sAttrib & "System "
-
If NOT oFile.Writeable Then sAttrib = sAttrib & "ReadOnly "
-
If sAttrib <> "" Then sReport.WriteLine "Attributes: " & sAttrib & vbcrlf
-
sAttrib = ""
-
Next
-
End Sub
-
-
' Revisions
-
' 15 Nov 2002 - Added MsgBox if no search matches found.
-
' 16 Nov 2002 - Added file attributes to the report
Popularidad: 27%

