嘿我正在尝试使用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
答案 0 :(得分: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