File/Directory Hierarchy Into XML? 
Author Message
 File/Directory Hierarchy Into XML?

I want to use the FileSystemInfo class in VB.NET to transform a
directory listing of files and subdirectories into a XML document. I
can't imagine that either this is already available in an existing
class or someone has posted code for this somewhere.

Does anyone have any pointers or URLs?

Thanks,
-Luke



Sat, 29 Jan 2005 01:58:36 GMT  
 File/Directory Hierarchy Into XML?
Hi Luke,

The following link contains C# sample for generating XML file using
FileSystemInfo class:

http://www.codeproject.com/csharp/xmldirectorylister.asp

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.              



Sat, 29 Jan 2005 06:18:05 GMT  
 File/Directory Hierarchy Into XML?

Quote:
> I want to use the FileSystemInfo class in VB.NET to transform a
> directory listing of files and subdirectories into a XML document

using System;
using System.Xml;
using System.IO;

namespace XMLUtils
{
 class DirectoryList
 {
  static XmlTextWriter _writer;
  static XmlNode _cur;

  [STAThread]
  static void Main(string[] args)
  {
    DirectoryInfo dir = new
DirectoryInfo(System.Environment.CurrentDirectory);
    _writer = new XmlTextWriter(dir.FullName + "/dirtoxml.xml"
,System.Text.Encoding.UTF8);
    _writer.Formatting = Formatting.Indented;
    _writer.WriteStartDocument();
     GetDirectories(dir);
    _writer.Wri{*filter*}dDocument();
    _writer.Flush();
    _writer.Close();
  }

  static void GetDirectories(DirectoryInfo dir)
  {
   _writer.WriteStartElement("directory");
    _writer.WriteAttributeString("path",dir.FullName);
    GetFiles(dir);
    foreach(System.IO.DirectoryInfo childdir in dir.GetDirectories())
    {
       GetDirectories(childdir);
    }
   _writer.Wri{*filter*}dElement();
  }

  static void GetFiles(DirectoryInfo dir)
  {
   foreach(System.IO.FileSystemInfo fi in dir.GetFileSystemInfos())
   {
    if (fi is System.IO.FileInfo)
    {
     FileInfo f = (FileInfo)fi;
     _writer.WriteStartElement("file");
     _writer.WriteAttributeString("name",f.Name);
     _writer.WriteAttributeString("length",f.Length.ToString());
     _writer.Wri{*filter*}dElement();
    }
   }
  }
 }

Quote:
}

--
Kirk Allen Evans
http://www.*-*-*.com/
"XML and ASP.NET", New Riders Publishing
  http://www.*-*-*.com/


Sat, 29 Jan 2005 09:01:22 GMT  
 File/Directory Hierarchy Into XML?
That was very helpful!

Thanks!

-Luke

On Mon, 12 Aug 2002 21:01:22 -0400, "Kirk Allen Evans"

Quote:



>> I want to use the FileSystemInfo class in VB.NET to transform a
>> directory listing of files and subdirectories into a XML document

>using System;
>using System.Xml;
>using System.IO;

>namespace XMLUtils
>{
> class DirectoryList
> {
>  static XmlTextWriter _writer;
>  static XmlNode _cur;

>  [STAThread]
>  static void Main(string[] args)
>  {
>    DirectoryInfo dir = new
>DirectoryInfo(System.Environment.CurrentDirectory);
>    _writer = new XmlTextWriter(dir.FullName + "/dirtoxml.xml"
>,System.Text.Encoding.UTF8);
>    _writer.Formatting = Formatting.Indented;
>    _writer.WriteStartDocument();
>     GetDirectories(dir);
>    _writer.Wri{*filter*}dDocument();
>    _writer.Flush();
>    _writer.Close();
>  }

>  static void GetDirectories(DirectoryInfo dir)
>  {
>   _writer.WriteStartElement("directory");
>    _writer.WriteAttributeString("path",dir.FullName);
>    GetFiles(dir);
>    foreach(System.IO.DirectoryInfo childdir in dir.GetDirectories())
>    {
>       GetDirectories(childdir);
>    }
>   _writer.Wri{*filter*}dElement();
>  }

>  static void GetFiles(DirectoryInfo dir)
>  {
>   foreach(System.IO.FileSystemInfo fi in dir.GetFileSystemInfos())
>   {
>    if (fi is System.IO.FileInfo)
>    {
>     FileInfo f = (FileInfo)fi;
>     _writer.WriteStartElement("file");
>     _writer.WriteAttributeString("name",f.Name);
>     _writer.WriteAttributeString("length",f.Length.ToString());
>     _writer.Wri{*filter*}dElement();
>    }
>   }
>  }
> }
>}

>--
>Kirk Allen Evans
> http://www.*-*-*.com/
>"XML and ASP.NET", New Riders Publishing
> http://www.*-*-*.com/



Tue, 08 Feb 2005 01:18:12 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. XML, Converting Word doc's to XML files (O'2000)

2. How to check file sizes & folder hierarchy

3. Returning all file names from given folder directory and all sub-directories

4. Naming files in a directory after the directory

5. How to delete files but keep the directory and sub directories

6. XML File vs Resource File

7. Import all files in directory into Access db--regardless of file name

8. Importing files from a directory where the file names are stored in a table

9. use of ADO to query file system (directories and files)

10. Write directory files to an seq file?

11. Selecting files in many directories, use of file list box

12. vbs file to print a file from a directory

 

 
Powered by phpBB® Forum Software