【问题标题】:XML with links & VB search & delete files extention带有链接和 VB 搜索和删除文件扩展名的 XML
【发布时间】:2013-08-08 09:03:53
【问题描述】:

我有一个 XML 文件,其中包含保存文件的路径。

<ROOT>
    <FILENAME>
         <LOCATION>E:\Test\</LOCATION>
    </FILENAME>
</ROOT>

使用这个 XML 文件,我希望 VB 使用这个链接来搜索 *.txt、*.log、*.csv 文件扩展名。 删除代码如下。

注意:我正在 SSIS 中编写脚本。

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Xml
Imports System.IO


Public Sub Main()
    Try

        For Each f In Directory.GetFiles("C:\Test\sample", "*.log", SearchOption.AllDirectories)
            System.IO.File.GetLastWriteTime("C:\Test\sample").ToLocalTime()
            File.Delete(f)
        Next

    Catch ex As UnauthorizedAccessException
        MsgBox(ex.Message)
    End Try

    Dts.TaskResult = ScriptResults.Success
End Sub

结束类

【问题讨论】:

    标签: xml vb.net ssis


    【解决方案1】:

    如何在 vb.net 中删除文件:

            Try
                File.Delete(PathAndFile)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    

    要获取文件的年龄:

           MsgBox(System.IO.File.GetLastWriteTime("c:\pagefile.sys").ToLocalTime)
    

    【讨论】:

      【解决方案2】:

      我想通了……

      Public Sub Main()
      
          'Declare the XML file.
          Dim xmldoc As New XmlDataDocument()
          Dim xmlnode As XmlNodeList
          Dim i As Integer
          Dim str As String
         'Get xml file and load it.
          Dim fs As New FileStream("C:\Test\sample.xml", FileMode.Open, FileAccess.Read)
          xmldoc.Load(fs)
          'Read the children. Case sensitive
          xmlnode = xmldoc.GetElementsByTagName("Area")
      
          For i = 0 To xmlnode.Count - 1
              xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
              str = xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
          MsgBox(str)
      

      只需要对删除位进行排序,因为输出可以通过 msgbox 看到,我正在寻找下一部分...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-17
        • 1970-01-01
        • 2013-09-26
        相关资源
        最近更新 更多