Re: Enumerate All file attributes by BerkHolz,
BerkHolz,
Thu Jul 03 16:07:05 CDT 2003
Here is a script to read attributes from files on CD or DVD.
You might find what you need in there.
Steven BerkHolz
------------------
'********************************************************************
'*
'* Script Name:
'*
'* archive.vbs
'*
'* Created:
'*
'* 2003-02-13, Steven BerkHolz (much code used as reference)
'*
'********************************************************************
'********************************************************************
'*
'* Global Variable Definitions
'*
'********************************************************************
'Option Explicit
dim WSHShell
dim WSHNet
dim fso
dim LogFile
dim FileCount
dim ShortCutCount
dim ChangeCount
dim CRLF
dim StartTime
'********************************************************************
'*
'* START! Call the MAIN function to get things started.
'*
'********************************************************************
Main()
LogFile.Close
Function Main()
InitGlobals()
On Error Resume Next
LogFile.WriteLine "Scan conducted for: " + WSHNet.UserDomain + "\" + _
WSHNet.UserName + " on " + WSHNet.ComputerName + " at " + CStr(Time) + ",
" + CStr(Date) + CRLF
If Err.Number <> 0 then
Err.Clear
LogFile.WriteLine "Scan conducted at " + CStr(Time) + ", " + CStr(Date) +
CRLF
If Err.Number <> 0 then
ErrorHandler True, "Unable to write to LogFile " + LogFile.Name, "Main()"
else
ErrorHandler False, "Unable to access user credentials.", "Main()"
end if
end if
On Error Goto 0
dim aDrive
Dim resulttoscan
resulttoscan = InputBox("Please enter the Drive letter to scan","Drive
letter","D", 100, 100)
Dim connA
Dim DataA
Dim AchiveMediaID
'AchiveMediaID = InputBox("Please enter the Archive Media ID to be
assigned","Archive Media ID","D", 100, 100)
'LogFile.WriteLine "Media ID to be assigned is " & AchiveMediaID
set connA = CreateObject("ADODB.Connection")
set DataA = CreateObject("ADODB.RecordSet")
connA.Open("Provider=SQLOLEDB; DATA SOURCE=tg01; Integrated Security=SSPI;
Persist Security Info=False; DATABASE=ArchiveDBSQL")
SQLTextA = "Select Max(MediaID) + 1 NextMediaID FROM MediaDB"
DataA.open SQLTextA, connA, 1
AchiveMediaID = DataA("NextMediaID")
LogFile.WriteLine "AchiveMediaID = " & AchiveMediaID
Dim blah
for each aDrive in fso.Drives
if aDrive.DriveLetter = resulttoscan Then
LogFile.WriteLine "scanning " & resulttoscan & " Drive started"
Dim string1
string1 = "Ready to scan, Please wait for Media ID. Close this window to
continue."
WScript.Echo(string1)
blah = SearchFolder (aDrive.RootFolder,AchiveMediaID)
If Err.Number <> 0 then
Err.Clear
LogFile.WriteLine "Scan conducted at " + CStr(Time) + ", " + CStr(Date) +
CRLF
If Err.Number <> 0 then
ErrorHandler True, "Unable to write to LogFile " + LogFile.Name,
"Main()"
else
ErrorHandler False, " Path not found.", "Main()"
end if
end if
LogFile.WriteLine "scanning " & resulttoscan & " Drive finished"
Dim string2
string2 = "The media ID is " & AchiveMediaID
WScript.Echo(string2)
end if
next
End Function
'************************************************************************
'*
'* Function: InitGlobals
'* Parameters: None
'* Purpose: Initialize global variables
'* Precondition: Global variables declared
'* Postcondition: Global variables initialized
'*
'************************************************************************
Sub InitGlobals()
On Error Resume Next
set WSHShell = WScript.CreateObject("WScript.Shell")
Set WSHNet = WScript.CreateObject("WScript.Network")
set fso = CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 then
ErrorHandler True, "Error creating VBScript object.", "InitGlobals()"
end if
set LogFile = fso.CreateTextFile("c:\ArhiveLog_" +
join(split(FormatDateTime(Time, vbShortTime),":"), "") + ".txt", True)
If Err.Number <> 0 then
ErrorHandler True, "Error creating file.", "InitGlobals()"
end if
FileCount = 0
ShortCutCount = 0
ChangeCount = 0
CRLF = Chr(13) & Chr(10)
StartTime = Time
End Sub
'************************************************************************
'*
'* Function: SearchFolder
'* Parameters: aFolder, Folder object
'* Purpose: Searches through all files in the given Folder.
'* Calls itself on all subfolders of aFolder
'* Precondition: aFolder is an existing Folder
'* Postcondition: If aFolder contained shortcuts to old server, they will
now
'* to point to the new server. Otherwise no change.
'*
'************************************************************************
Function SearchFolder(aFolder,MediaIDName)
if aFolder.Name = "System Volume Information" then Exit Function
'^^^ Nobody has access to this dir by default, so accessing it throws an
error.
dim aFile
On Error Resume Next
Dim Data2
set conn2 = CreateObject("ADODB.Connection")
SET Data2 = CreateObject("ADODB.RecordSet")
conn2.Open("Provider=SQLOLEDB; DATA SOURCE=tg01; Integrated Security=SSPI;
Persist Security Info=False; DATABASE=ArchiveDBSQL")
SQLText2 = "Select " & _
"MediaDB.ID, MediaDB.MediaID, MediaDB.ScannedBy, MediaDB.ScannedOn, " & _
"MediaDB.FileName, MediaDB.FileType, MediaDB.FileAttrib, MediaDB.FileDateC,
MediaDB.FileDateM, MediaDB.FilePath, MediaDB.FileSize, MediaDB.FileVersion "
& _
"FROM " & _
"MediaDB " & _
"WHERE " & _
"ID > 0 ORDER BY " & _
"ID ASC"
'WScript.Echo MediaID2
'MediaID3 = Data("MediaID").value
'LogFile.WriteLine "MediaID3 = " & MediaID3
Data2.Open SQLText2, conn2, 3,3
for each aFile in aFolder.Files
If Err.Number <> 0 then
ErrorHandler False, "Error accessing folder " + aFolder, "SearchFolder("
+ aFolder + ")"
Exit Function
end If
Dim PathLen
Dim NewPathLen
Dim RightPath
Dim RightPathLen
LogFile.WriteLine "Name = " & aFile.Name
LogFile.WriteLine "Type = " & aFile.Type
LogFile.WriteLine "Attributes = " & aFile.Attributes
LogFile.WriteLine "DateCreated = " & aFile.DateCreated
LogFile.WriteLine "DateLastModified = " & aFile.DateLastModified
PathLen = Len(aFile.Path)
NewPathLen = PathLen - 2
RightPath = Right(aFile.Path, NewPathLen)
RightPathLen = Len(RightPath)
PathLen = Len(aFile.Name)
NewPathLen = RightPathLen - PathLen
LogFile.WriteLine "Path = " & Left(RightPath, NewPathLen)
LogFile.WriteLine "Size = " & aFile.Size
LogFile.WriteLine "Version = " & fso.GetFileVersion(aFile)
LogFile.WriteLine CRLF
Data2.AddNew
Data2.Fields("MediaID").Value = MediaIDName
Data2.Fields("ScannedBy").Value = WSHNet.UserName
Data2.Fields("ScannedOn").Value = CStr(Date)
Data2.Fields("FileName").Value = aFile.Name
Data2.Fields("FileType").Value = aFile.Type
Data2.Fields("FileAttrib").Value = aFile.Attributes
Data2.Fields("FileDateC").Value = aFile.DateCreated
Data2.Fields("FileDateM").Value = aFile.DateLastModified
Data2.Fields("FilePath").Value = Left(RightPath, NewPathLen)
Data2.Fields("FileSize").Value = aFile.Size
Data2.Fields("FileVersion").Value = fso.GetFileVersion(aFile)
Data2.Update
If Err.Number <> 0 then
ErrorHandler False, "Error accessing file " + aFile, "SearchFolder(" +
aFolder + ")"
end if
FileCount = FileCount + 1
Next
dim SubFolder
for each SubFolder in aFolder.SubFolders
If Err.Number <> 0 then
ErrorHandler False, "Error accessing subfolder " + SubFolder,
"SearchFolder(" + aFolder + ")"
Exit Function
end if
Dim blah2
if SubFolder.Type <> "Folder Shortcut" then
blah2 = SearchFolder (SubFolder,MediaIDName)
end if
next
On Error Goto 0
End Function
'************************************************************************
'*
'* Function: ErrorHandler
'* Parameters: Fatal, boolean
'* Description, string
'* FunctionName, string
'* Purpose: Tests the severity of the error, logs the appropriate
'* message, Displays an appropriate message if needed,
'* and exits the script if the error is fatal
'* Precondition: An error has occurred (Thus, Err object populate with
meaningful data)
'*
'************************************************************************
Function ErrorHandler(Fatal, Description, FunctionName)
dim String
String = "Fatal Error - " + CStr(DateDiff("s", StartTime, Time)) + "
seconds into the script." + CRLF + _
" In Function " + FunctionName + CRLF + _
" VBS Info:" + CRLF + _
" Description: " + Chr(9) + Err.Description + CRLF + _
" Error Number: " + Chr(9) + CStr(Err.Number) + CRLF + _
" Error Source: " + Chr(9) + Err.Source + CRLF + _
" FixLinks Info:" + CRLF + _
" Description: " + Chr(9) + Description
if CBool(Fatal) then
LogFile.WriteLine String
LogFile.Close
String = "FixLinks.vbs Error!" + CRLF + _
"An error has occurred during the execution of this script." + CRLF + _
"Errors have been printed to the Log File." + CRLF + _
"Please contact your Network Administrator for assistance."
WSHShell.Popup String, 999, "FixLinks", 16
wscript.quit 1
else
String = "Non-" + String
LogFile.WriteLine String
Err.Clear
end if
End Function
-------------------
"Bioman" <azeem.mohammed@biovail.com> wrote in message
news:ca96a5fd.0307031113.8bf901a@posting.google.com...
> anyone have a script that will return the file attributes of all files
> in a folder and it's subfolders?
>
> Thanks
> azeem.