' ListFileStructureToXML.vbs
Option Explicit
Dim fs, TotalBytes, TotalFiles, Log, prevFolder
If WScript.Version < "5.6" Then Usage("Windows Script 5.6 or greater required")
Call Main("C:\Temp")
Sub Main(FolderPath)
Dim LogFile, ScriptPath, ReportPath, ReportFileExists, Folder, Attribute, Root, f, sTmp
Const ForReading = 1
Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIt = True
Const vbInformation = 64
Const vbExclaimation = 48
Const vbQuestion = 32
Const vbCritical = 16
If Right(FolderPath, 1) = "\" Then FolderPath = Left(FolderPath, Len(FolderPath) - 1) ' Remove trailing back-slash
If Len(FolderPath) < 4 Then
Folder = ""
Else
Folder = Right(FolderPath, Len(FolderPath) - 3) ' Path without drive, e.g. "C:\Temp\folder" becomes "Temp\folder"
End If
Root = Left(FolderPath, 2) ' Should contain "C:"
ScriptPath = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
ReportPath = ScriptPath
TotalBytes = 0
TotalFiles = 0
Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.FolderExists(Root & "\" & Folder) Then
MsgBox "Specified folder does not exist!" & vbCrLf & vbCrLF & Root & "\" & Folder & vbCrLf & vbCrLf & "Please check your input parameters.", vbExclaimation,"Folder missing"
Set fs = nothing
WScript.Quit
End If
' Create and open the Log File
LogFile = ReportPath & "ListFileStructureToXML.xml"
Set Log = fs.OpenTextFile(LogFile, ForWriting, CreateIt, OpenAsASCII)
Log.writeline "<?xml version=""1.0""?>"
Log.Writeline "<Root>"
' Get the file list
GetFileList Root & "\" & Folder
' Get the Folder List
GetFolderList Root, Folder
If TotalFiles = 0 Then
Log.Writeline "<file />"
End If
Log.Writeline "<SearchResult>"
Log.Writeline "<SearchLocation>" & Root & "\" & Folder & "</SearchLocation>"
Log.Writeline "<TotalNoOfFiles>" & TotalFiles & "</TotalNoOfFiles>"
Log.Writeline "<TotalNoOfBytes>" & TotalBytes & "</TotalNoOfBytes>"
Log.Writeline "</SearchResult>"
Log.Writeline "</Root>"
If TotalFiles > 0 Then
Wscript.CreateObject("WScript.Shell").Run LogFile
Else
MsgBox "No files found for the specified path:" & vbCrLf & vbCrLf & Root & "\" & Folder, vbInformation, "No files found..."
End If
Set fs = Nothing
End Sub
Sub GetFolderList(root,folderspec)
Dim f, f1, sf
Set f = fs.GetFolder(root & "\" & folderspec)
Set sf = f.SubFolders
For Each f1 In sf
GetFileList root & "\" & folderspec & "\" & f1.name
GetFolderList root & "\" & folderspec, f1.name
Next
End Sub
Sub GetFileList(folderspec)
Dim f, f1, fc, sTmp(2), extension
Set f = fs.GetFolder(folderspec)
If prevFolder <> f Then Log.Writeline "<Folder name=""" & f & """>"
Set fc = f.Files
For Each f1 in fc
extension = fs.GetExtensionName(folderspec & "\" & f1.name)
sTmp(0) = GetFileInfo(1, folderspec & "\" & f1.name)
sTmp(1) = GetFileInfo(2, folderspec & "\" & f1.name)
Log.Writeline "<file name=""" & f1.name & """ size=""" & sTmp(0) & """ access=""" & sTmp(1) & """ type=""" & extension & """ />"
Next
If prevFolder <> f Then
prevFolder = f
Log.Writeline "</Folder>"
End If
End Sub
Function GetFileInfo(info, filespec)
Dim f, RO, s
Set f = fs.GetFile(filespec)
If info = 1 Then
s = f.size 'file size in bytes
TotalBytes = TotalBytes + s 'note the size
TotalFiles = TotalFiles + 1 'Count it.
End If
If info = 2 Then RO = (f.attributes and 1) 'RO=1=Read only; RO=0=Not Read only
If info = 1 Then
GetFileInfo = s
ElseIf (RO = 0) And info = 2 Then 'If it's not RO and...
GetFileInfo = "Read-Write"
ElseIf (RO = 1) And info = 2 Then 'If it is ReadOnly...
GetFileInfo = "Read-Only "
End If
End Function
Detta ska fungera tror jag... Spara skriptet som *.vbs och kör det så ska du få resultatet i en browser.
Det är rätt enkelt att modifera för VBScript för HTML också. Dock kan FSO (File Scripting Object) ställa till det lite på en webb sida.