带链接的XML和VB搜索和删除文件扩展名

时间:2023-01-14 23:58:34

I have an XML file that has paths to where files are kept.

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

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

Using this XML file, I want VB to use this link to search for *.txt, *.log, *.csv file extensions. Deleting code as follows.

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

NB: I'm scripting in SSIS.

注意:我正在使用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

End Class

2 个解决方案

#1


0  

How to delete a file in vb.net:

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

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

To get the age of a file:

要获取文件的年龄:

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

#2


0  

I figured this out...

我想出来了......

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)

Just need to sort the deleting bit out as the output can be seen by the msgbox, I am looking for this next part...

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

#1


0  

How to delete a file in vb.net:

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

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

To get the age of a file:

要获取文件的年龄:

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

#2


0  

I figured this out...

我想出来了......

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)

Just need to sort the deleting bit out as the output can be seen by the msgbox, I am looking for this next part...

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