Code to create entire file system as XML File in VB.NET
Code to create entire file system as XML File in VB.NET
Rate Code to create entire file system as XML File in VB.NET
(1(1 Vote))
Imports System
Imports System.IO
Imports Microsoft.VisualBasic.Compatibility.VB6.FileSystem
Imports Microsoft.VisualBasic.Compatibility.VB6
Imports Microsoft.VisualBasic
Module General
Dim g_oWriter As New MSXML2.MXXMLWriter() 'create instance of xml writer object
Public Sub Main()
Dim sPath As String
Call FindSubFolders("c:\")
If g_oWriter.output <> "" Then Call CreateFile()
MsgBox("File Has Been Created", MsgBoxStyle.Information, "Done")
g_oWriter.output = vbNullString
g_oWriter = Nothing
End Sub
Private Function FindSubFolders(ByVal sPath_In As String) As Boolean
Dim oDirs() As Directory
Dim oFolder As Directory
Dim sPath As String
Dim lDirCnt As Long
Try
oDirs = system.IO.Directory.GetDirectoriesInDirectory(sPath_In)
If oDirs.Length > 0 Then g_oWriter.startElement_2("", "Directory", "Directory", Nothing)
For Each oFolder In oDirs
With g_oWriter
.startElement_2("", "D" & CStr(lDirCnt), "D" & CStr(lDirCnt), Nothing)
.characters_2(oFolder.ToString)
.endElement_2("", "D" & CStr(lDirCnt), "D" & CStr(lDirCnt))
End With
Call FindFiles(oFolder.ToString)
sPath_In = oFolder.ToString
Call FindSubFolders(sPath_In)
lDirCnt = lDirCnt + 1
Next
If oDirs.Length > 0 Then g_oWriter.endElement_2("", "Directory", "Directory")
Catch
End Try
FindSubFolders = True
End Function
Private Sub FindFiles(ByVal sPath_In As String)
Dim oFiles() As File
Dim oFile As File
Dim lFileCnt As Long
Try
oFiles = System.IO.Directory.GetFilesInDirectory(sPath_In)
'Create filename element
If oFiles.Length > 0 Then g_oWriter.startElement_2("", "FileName", "FileName", Nothing)
For Each oFile In oFiles
With g_oWriter
.startElement_2("", "F" & CStr(lFileCnt), "F" & CStr(lFileCnt), Nothing)
.characters_2(oFile.ToString)
.endElement_2("", "F" & CStr(lFileCnt), "F" & CStr(lFileCnt))
End With
lFileCnt = lFileCnt + 1
Next
If oFiles.Length > 0 Then g_oWriter.endElement_2("", "FileName", "FileName")
Catch
End Try
End Sub
Private Function CreateFile() As Boolean
open(1, "c:\directory.xml", OpenMode.Output)
Print(1, g_oWriter.output)
close(1)
End Function
End Module
Code to create entire file system as XML File in VB.NET Comments
No comments yet — be the first to post one!
Post a Comment