0

该程序从今天已修改的文件夹中提取文件,并将文件放入另一个文件夹后,批处理文件会删除该源文件夹中其余未修改的文件。

我的程序应该做的最后一件事是从单独的文件夹中复制文件,然后将它们放回该源文件夹中。

但是我的程序只提取修改后的文件,删除该文件夹中的其余文件,但是当我运行程序以复制并将新文件放入源文件夹时,它只是不这样做。有谁知道为什么?

Imports System.IO

Public Class frmExtractionator

    '  Dim txtFiles1 As Control
    Dim sourceDirectory As String = "F:\CopierFolderforTestDriveCapstone"
    Dim archiveDirectory As String = "F:\FilesExtracted"
    Dim originalDirectory As String = "F:\OriginalTestFiles"

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

        Try

            Dim txtFiles = Directory.EnumerateFiles(sourceDirectory)

            If (Not System.IO.Directory.Exists(archiveDirectory)) Then
                System.IO.Directory.CreateDirectory(archiveDirectory)
            End If


            For Each currentFileLoc As String In txtFiles

                Dim fileName = currentFileLoc.Substring(sourceDirectory.Length + 1)



                If (IO.File.GetLastWriteTime(currentFileLoc).ToString("MM/dd/yyyy") = DateTime.Now.ToString("MM/dd/yyyy")) Then
                    MessageBox.Show(currentFileLoc & " moved", "Moved Succesfully")
                    File.Move(currentFileLoc, Path.Combine(archiveDirectory, fileName))

                End If

            Next
        Catch eT As Exception
            Console.WriteLine(eT.Message)
        End Try

        System.Diagnostics.Process.Start("F:\poop.bat")


        Try
            Dim txtFiles2 = Directory.EnumerateFiles(originalDirectory)

            For Each currentFileLoc2 As String In txtFiles2

                Dim fileName = currentFileLoc2.Substring(originalDirectory.Length + 1)

                File.Move(currentFileLoc2, Path.Combine(sourceDirectory, fileName))

            Next
        Catch eT As Exception
            Console.WriteLine(eT.Message)
        End Try
    End Sub

End Class
4

1 回答 1

0

改变

Dim fileName = currentFileLoc2.Substring(originalDirectory.Length + 1)

Dim FileName = IO.Path.GetFileName(currentFileLoc2)
于 2013-04-14T17:24:53.950 回答