我正在修改文件复制程序,该程序过去只将一个目录复制到另一个目录。现在,我希望在一个列表中传递目录和文件,以便运行副本。
For Each _fromPath In CopyList
Dim FSinfo As FileSystemInfo()
If Directory.Exists(_fromPath) Then
Dim dir As New DirectoryInfo(_fromPath)
FSinfo = dir.GetFileSystemInfos
ElseIf File.Exists(_fromPath) Then
Dim file As New FileInfo(_fromPath)
FSinfo = file
End If
CountFiles(FSinfo)
Next
Private Function CountFiles(ByVal FSInfo As FileSystemInfo()) As Boolean此代码适用于目录。为了传递到CountFiles的路径,它们必须在FileSystemInfo中。是否有FileInfo作为FileSystemInfo的代名词。
我试过CType(file, FileSystemInfo),但上面写着Value of type 'System.IO.FileInfo' cannot be converted to '1-dimensional array of System.IO.FileSystemInfo'.
发布于 2014-05-18 16:43:30
一个问题是,您试图将一个对象(FileInfo)转换为一个对象数组(FileSystemInfo()),这正是错误消息试图告诉您的。您可以编写一个重载的函数来处理其中的一些问题:
' my Count functions return numeric values:
Private Function CountFiles(FSInfo As FileSystemInfo()) As Integer
Private Function CountFiles(FInfo As FileInfo) As Integer在它们内部,FileSystemInfo可能会在循环中调用另一个代码以避免重复代码,或者它们可能都调用了一个公共过程,这取决于它是如何编写的。
https://stackoverflow.com/questions/23724193
复制相似问题