我试着用了一种变通的办法,设想一般我们公司的文件夹也就四、五层,我就预设了八层,不用getfiles, 只是反复套用getdirectories,fileexist,和copyfile, 虽说有点繁琐,但试运行了一下还勉强能凑合,
试搜了1000个文件出来,花了1分钟左右, 如果找不到更好的办法,就这么将就着用着先
此主题相关图片如下:找图片.jpg
Dim stx As String = Forms("FINDPIC").Controls("TBoxPath").Text
Dim ctx As String = Forms("FINDPIC").Controls("TBoxPathSave").Text
If DataTables("FINDLIST").DataRows(0).IsNull("orignialname") Then
MessageBox.Show("把待搜清单粘贴到这里","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Forms("FINDPICLST").Open
Return
Else If stx.Length < 2 Then
MessageBox.Show("你打算搜哪个文件夹?","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
Else If ctx.Length < 2 Then
MessageBox.Show("你打算存在哪里?","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
End If
MessageBox.Show("目录层数比较的话会慢些,耐性等一会儿吧","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Dim dir0 As String = Forms("FINDPIC").Controls("TBoxPath").Text
Dim savepath As String = Forms("FINDPIC").Controls("TBoxPathSave").Text
Dim picfmt As String =Forms("FINDPIC").Controls("fmtTexbox").text ' 从单选框获得文件文件扩展名存
Dim names As List(Of String)
names = DataTables("FINDLIST").GetValues("orignialname")' 获得原始待搜文件清单
For i As Integer = 1 To names.Count-1
names(i) = "\" & names(i) & picfmt ' 加上扩展名
Next
names.RemoveAt(0) ' 去掉第一个空值
'根目录搜索
For Each name As String In names
If FileSys.FileExists(dir0 & name) Then
FileSys.CopyFile( dir0 & name, savepath & name, True)
End If
Next
'二级目录搜索
For Each dir1 As String In FileSys.GetDirectories(dir0)
For Each name As String In names
If FileSys.FileExists(dir1 & name) Then
FileSys.CopyFile( dir1 & name, savepath & name, True)
End If
Next
Next
'三级目录搜索
For Each dir1 As String In FileSys.GetDirectories(dir0)
For Each dir2 As String In FileSys.GetDirectories(dir1)
For Each name As String In names
If FileSys.FileExists(dir2 & name) Then
FileSys.CopyFile( dir2 & name, savepath & name, True)
End If
Next
Next
Next
'四级目录搜索
For Each dir1 As String In FileSys.GetDirectories(dir0)
For Each dir2 As String In FileSys.GetDirectories(dir1)
For Each dir3 As String In FileSys.GetDirectories(dir2)
For Each name As String In names
If FileSys.FileExists(dir3 & name) Then
FileSys.CopyFile( dir3 & name, savepath & name, True)
End If
Next
Next
Next
Next
'五级目录搜索
For Each dir1 As String In FileSys.GetDirectories(dir0)
For Each dir2 As String In FileSys.GetDirectories(dir1)
For Each dir3 As String In FileSys.GetDirectories(dir2)
For Each dir4 As String In FileSys.GetDirectories(dir3)
For Each name As String In names
If FileSys.FileExists(dir4 & name) Then
FileSys.CopyFile( dir4 & name, savepath & name, True)
End If
Next
Next
Next
Next
Next
'六级目录搜索
For Each dir1 As String In FileSys.GetDirectories(dir0)
For Each dir2 As String In FileSys.GetDirectories(dir1)
For Each dir3 As String In FileSys.GetDirectories(dir2)
For Each dir4 As String In FileSys.GetDirectories(dir3)
For Each dir5 As String In FileSys.GetDirectories(dir4)
For Each name As String In names
If FileSys.FileExists(dir5 & name) Then
FileSys.CopyFile( dir5 & name, savepath & name, True)
End If
Next
Next
Next
Next
Next
Next
'七级目录搜索
For Each dir1 As String In FileSys.GetDirectories(dir0)
For Each dir2 As String In FileSys.GetDirectories(dir1)
For Each dir3 As String In FileSys.GetDirectories(dir2)
For Each dir4 As String In FileSys.GetDirectories(dir3)
For Each dir5 As String In FileSys.GetDirectories(dir4)
For Each dir6 As String In FileSys.GetDirectories(dir5)
For Each name As String In names
If FileSys.FileExists(dir6 & name) Then
FileSys.CopyFile( dir6 & name, savepath & name, True)
End If
Next
Next
Next
Next
Next
Next
Next
'八级目录搜索
For Each dir1 As String In FileSys.GetDirectories(dir0)
For Each dir2 As String In FileSys.GetDirectories(dir1)
For Each dir3 As String In FileSys.GetDirectories(dir2)
For Each dir4 As String In FileSys.GetDirectories(dir3)
For Each dir5 As String In FileSys.GetDirectories(dir4)
For Each dir6 As String In FileSys.GetDirectories(dir5)
For Each dir7 As String In FileSys.GetDirectories(dir6)
For Each name As String In names
If FileSys.FileExists(dir7 & name) Then
FileSys.CopyFile( dir7 & name, savepath & name, True)
End If
Next
Next
Next
Next
Next
Next
Next
Next
MessageBox.Show("搜完了","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
DataTables("FINDLIST").DeleteFor("orignialname Is Not Null")