Hi,
I am trying to get some file properties and write it to a file "Files.log" and if error occurs it calls for a function OnError.But, when a file property has value with chinese/japanese/russian etc.. characters (which I am unable to copy/paste), however it shows correctly when I retrieve those values in msgbox but it doesn't write anything to a file as it doesn't understand the characters, though its writing correctly the characters such as é
The Error is also not generated properly as for some only "--------------------------------------------" would come without writing the Errors and always at the last of the o/p file an extra OnError function is executed without Folder data .
The below script takes dir.txt having only directories by using the shell command "cmd /c dir /s /b /ad C:\ > dir.txt" and than retrieves the file properties along with the errors;
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set winsh = CreateObject("WScript.Shell")
Set winenv = winsh.Environment("Process")
windir = winenv("WINDIR")
StrFNam = windir &"\temp\dir.txt"
StrFileName = windir &"\temp\Files.log"
Const ForWriting = 2, ForReading = 1, ForAppending = 8
arrLines = Split(objFSO.OpenTextFile(StrFNam).ReadAll(), VbCrLf)
Set objTextFile = objFSO.OpenTextFile(StrFileName,ForWriting,TRUE)
Const n = 5
i = -1
count = 0
Set objFolder = objShell.Namespace("C:\")
Do
i = i + 1
attr = objFolder.GetDetailsOf(objFolder.Items, i)
Select Case LCase(attr)
Case "company" : indexCompany = i
Case "product name" : indexName = i
Case "product version" : indexVersion = i
Case "copyright" : indexCopyR = i
Case "file description" : indexDesc = i
End Select
If attr = "" Then
count = count + 1
Else
count = 0
End If
Loop Until count >= n
For i=0 To UBound(arrLines)
strPath = arrLines(i)
On Error Resume Next
For Each f In objFSO.GetFolder(strPath).Files
If Err Then
OnError(objTextFile)
Else
FileName = f.Name
FileVersion = objFSO.GetFileVersion(f.Path)
Set objFolder = objShell.Namespace(strPath)
Set objFile = objFolder.ParseName(FileName)
If indexCompany <> "" Then Company= objFolder.GetDetailsOf(objFile, indexCompany)
If indexName <> "" Then ProductName= objFolder.GetDetailsOf(objFile, indexName)
If indexVersion <> "" Then ProductVersion= objFolder.GetDetailsOf(objFile, indexVersion)
If indexCopyR <> "" Then Copyright= objFolder.GetDetailsOf(objFile, indexCopyR)
If indexDesc <> "" Then FileDesc= objFolder.GetDetailsOf(objFile, indexDesc)
'MsgBox(strPath)
'MsgBox(f.Name)
'MsgBox(FileDesc)
'MsgBox(Copyright)
StrText = "FileName: " &FileName & vbNewLine & "FileVersion: " &FileVersion & vbNewLine & "ProductName: " &ProductName & vbNewLine & "ProductVersion:" &ProductVersion & vbNewLine & "Company: " &Company & vbNewLine & "FileSize: " & f.Size & vbNewLine & "LastModifiedDate: " &f.DateLastModified & vbNewLine & "CreatedDate:" &f.DateCreated & vbNewLine & "ParentFolder: " &strPath
StrText = "FileName: " &FileName & vbNewLine
If FileVersion <> "" Then StrText = StrText & "FileVersion: " &FileVersion & vbNewLine
If ProductName <> "" Then StrText = StrText & "ProductName: " &ProductName & vbNewLine
If ProductVersion <> "" Then StrText = StrText & "ProductVersion: " &ProductVersion & vbNewLine
If Company <> "" Then StrText = StrText & "Company: " &Company & vbNewLine
StrText = StrText & "FileSize: " & f.Size & vbNewLine & "LastModifiedDate: " &f.DateLastModified & vbNewLine &"CreatedDate: " &f.DateCreated & vbNewLine
If FileDesc <> "" Then StrText = StrText & "FileDescription: " &FileDesc & vbNewLine
If Copyright <> "" Then StrText = StrText & "Copyright: " &Copyright & vbNewLine
StrText = StrText & "ParentFolder: " &strPath
objTextFile.WriteLine(StrText)
objTextFile.WriteLine("-------------------------------------------------------------")
End If
FileName = ""
Next
On Error GoTo 0
Next
Function OnError(objTextFile)
objTextFile.WriteLine("Folder: " & strPath)
objTextFile.WriteLine("Error: " & Err.Number)
objTextFile.WriteLine("Source: " & Err.Source)
objTextFile.WriteLine("Description: " & Err.Description)
objTextFile.WriteLine("-------------------------------------------------------------")
Err.Clear
End Function
Example output;
=================
-------------------------------------------------------------
Folder: C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.ARCSERVE_DB\MSSQL\Binn\Resources\1028
Error: 5
Source: Microsoft VBScript runtime error
Description: Invalid procedure call or argument
-------------------------------------------------------------
FileName: xplog70.rll
FileVersion: 2007.100.1600.22
ProductName: Microsoft SQL Server
ProductVersion: 10.0.1600.22
Company: Microsoft Corporation
FileSize: 14360
LastModifiedDate: 3/31/2009 10:26:06 AM
CreatedDate: 3/31/2009 10:26:06 AM
FileDescription: SQL Server Extended Stored Procedure DLL
Copyright: Microsoft Corp. All rights reserved.
ParentFolder: C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.ARCSERVE_DB\MSSQL\Binn\Resources\1028
-------------------------------------------------------------
FileName: xplog70.rll
FileVersion: 2007.100.1600.22
ProductName: Microsoft SQL Server
ProductVersion: 10.0.1600.22
Company: Microsoft Corporation
FileSize: 14360
LastModifiedDate: 3/31/2009 10:26:06 AM
CreatedDate: 3/31/2009 10:26:06 AM
FileDescription: DLL de procedimento armazenado estendido do SQL Server
Copyright: Microsoft Corporation. Todos os direitos reservados.
ParentFolder: C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.ARCSERVE_DB\MSSQL\Binn\Resources\1046
-------------------------------------------------------------
-------------------------------------------------------------
Folder: C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.ARCSERVE_DB\MSSQL\Binn\Resources\1049
Error: 5
Source: Microsoft VBScript runtime error
Description: Invalid procedure call or argument
-------------------------------------------------------------
-------------------------------------------------------------
-------------------------------------------------------------
Folder: C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.ARCSERVE_DB\MSSQL\Binn\Resources\2052
Error: 5
Source: Microsoft VBScript runtime error
Description: Invalid procedure call or argument
-------------------------------------------------------------
-------------------------------------------------------------
FileName: odsole70.rll
FileVersion: 2007.100.1600.22
ProductName: Microsoft SQL Server
ProductVersion: 10.0.1600.22
Company: Microsoft Corporation
FileSize: 22552
LastModifiedDate: 3/31/2009 10:26:06 AM
CreatedDate: 3/31/2009 10:26:06 AM
FileDescription: OleAut driver DLL containing SQL Server sp_OA extended stored procedures
Copyright: Microsoft Corp. Reservados todos los derechos.
ParentFolder: C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.ARCSERVE_DB\MSSQL\Binn\Resources\3082
-------------------------------------------------------------
FileName: xplog70.rll
FileVersion: 2007.100.1600.22
ProductName: Microsoft SQL Server
ProductVersion: 10.0.1600.22
Company: Microsoft Corporation
FileSize: 14872
LastModifiedDate: 3/31/2009 10:26:06 AM
CreatedDate: 3/31/2009 10:26:06 AM
FileDescription: SQL Server Extended Stored Procedure DLL
Copyright: Microsoft Corp. Reservados todos los derechos.
ParentFolder: C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.ARCSERVE_DB\MSSQL\Binn\Resources\3082
-------------------------------------------------------------
Folder:
Error: 5
Source: Microsoft VBScript runtime error
Description: Invalid procedure call or argument
-------------------------------------------------------------=========================================
Please help me to get the file details even if chinese/japanese/Russian or any such characters are there may be doing some conversions if such characters are there to their relative other standard format notations through which by seeing the o/p file I can atleast know what would have been the actual character.
However, I tried to write the output file in UNICODE format but question marks are coming up for those unknown characters(?) and also the size is double which is a real concern, hence can't use that.
And sorry, I can't use powershell scripts for this.