2

嘿,我正在尝试使用 EnumerateFiles 函数,但是当我尝试运行我的程序时,它说:错误 BC30616:变量 'e' 在封闭块中隐藏了一个变量

有人可以帮忙吗?非常感谢!

Imports System.IO

Public Class frmExtractionator

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

        Dim sourceDirectory As String = "F:\CopierFolderforTestDriveCapstone"
        Dim archiveDirectory As String = "F:\FilesExtracted"

        Try
            Dim txtFiles = Directory.EnumerateFiles(sourceDirectory)

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

            For Each currentFile As String In txtFiles
                Dim fileName = currentFile.Substring(sourceDirectory.Length + 1)
                File.Move(currentFile, Path.Combine(archiveDirectory, fileName))
            Next
        Catch eT As Exception
            Console.WriteLine(eT.Message)
        End Try

    End Sub
End Class
4

1 回答 1

1

试试这个改变

原因变量:e 被使用了两次

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

e已经在哪里使用了?

btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

更新: 关于您的疑问:

 Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName))

我认为您正在尝试移动文件而不是目录,对吗?

改用 File.Move ,记得创建archiveDirectory

update2: 之前将其添加到您的代码中For Each

If(Not System.IO.Directory.Exists(archiveDirectory )) Then
    System.IO.Directory.CreateDirectory(archiveDirectory )
End If
于 2013-03-25T00:16:46.017 回答