Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
File Folder Hirerchy to XML
Author:
Ajay
E-mail:
Click to e-mail author
Submitted:
2/23/2008
Version:
VB.NET 2003
Compatibility:
VB.NET 2003, VB 2005, VB 2008
Category:
File Manipulation
Views:
10910
This code generates an XML file in the given directory with contents same as Explorer hierarchy. It also displays the files size and change date including folders description like Number of files or folders. It can be used when you want to make a CD/DVD with many number of files and this xml file helps to find out the files/folders snapshots in a single look.
Declarations:
Imports System.IO Dim Trgt As StreamWriter Dim T1 As Threading.Thread 'Place on Textbox and and button. Give the path of 'the root folder in textbox1 and click the button.
Code:
Sub CreateXMLPath() Trgt = New StreamWriter(TextBox1.Text & "\index.xml") Trgt.WriteLine(" ") Trgt.WriteLine("
") Text = "Started" Trgt.WriteLine("
Ajay
") Trgt.WriteLine("
" & DateTime.Now & "
") ScanFolder(TextBox1.Text) Trgt.WriteLine("
") Trgt.Close() Text = "Completed" End Sub Sub ScanFolder(ByVal FldName As String) 'On Error GoTo NextSub Dim S As String Dim TotFiles, TotFolders, TotSize As Long Dim sZ As Double Dim Fld As New DirectoryInfo(FldName), Fl As FileInfo Dim MainFld As New DirectoryInfo(FldName) Trgt.WriteLine("
") For Each Fld In MainFld.GetDirectories Text = "Scanning folder " & FldName ScanFolder(Fld.FullName()) TotFolders += 1 Next For Each Fl In MainFld.GetFiles TotFiles += 1 S = Fl.FullName If Fl.Name <> "index.xml" Then sZ = Math.Round(Fl.Length / 1024, 2) Trgt.WriteLine("
") TotSize += Fl.Length End If Next Trgt.WriteLine("
") Trgt.WriteLine("
") NextSub: End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click T1 = New Threading.Thread(AddressOf CreateXMLPath) T1.Start() End Sub 'Replace the invalid charactes for XML with valid one Function ParseXML(ByVal S As String) As String S = S.Replace("&", "&") S = S.Replace("'", "") S = S.Replace("""", "") Return S End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement