zoukankan      html  css  js  c++  java
  • 将文件及文件夹路径 转为 xml

    将文件及文件夹路径 转为 xml ,加速查询



    Public Shared Function ScanFileInfo2Xml(ByVal FolderPath As String) As XDocument Dim fiXml As XDocument fiXml = XDocument.Parse("<FileInfoList rootdir = '" & FolderPath & "'>" & AddDirFiles(FolderPath) & "</FileInfoList>") Return fiXml End Function Public Shared Function AddDirFiles(ByVal DirPath As String) As String Dim diTop As New DirectoryInfo(DirPath) Dim sr As String = "" Try For Each fi In diTop.EnumerateFiles("*", SearchOption.TopDirectoryOnly) Try ' 输出每一个文件 sr = sr & "<filename>" & fi.Name & "</filename>" Catch unAuthTop As UnauthorizedAccessException Console.WriteLine($"{unAuthTop.Message}") End Try Next For Each di In diTop.EnumerateDirectories("*") Try sr = sr & "<Directory value = '" & di.Name & "'>" & AddDirFiles(di.FullName) & "</Directory>" Catch unAuthSubDir As UnauthorizedAccessException Console.WriteLine($"unAuthSubDir: {unAuthSubDir.Message}") End Try Next Catch dirNotFound As DirectoryNotFoundException Console.WriteLine($"{dirNotFound.Message}") Catch unAuthDir As UnauthorizedAccessException Console.WriteLine($"unAuthDir: {unAuthDir.Message}") Catch longPath As PathTooLongException Console.WriteLine($"{longPath.Message}") End Try Return sr End Function
  • 相关阅读:
    UVA10891
    UVA10453
    UVA 10201
    UVA10154
    UVA11137
    UVA10617
    UVA10271
    UVA10739
    UVA10306
    节流防抖
  • 原文地址:https://www.cnblogs.com/MadeInChinese/p/14132940.html
Copyright © 2011-2022 走看看