[英]How to search foldernames and zip found folders with Visual Basic.NET?
[英]How search for a folder and copy the folder in visual basic.net?
我找不到如何搜索包含字符串的文件夹(目录)并将包含该字符串的所有文件夹(目录)复制到另一个目录的方法。 因此,您搜索目录的名称,而不是目录中的文件。 例如:E:\\中的'KTNPRK'给出:E:\\ KTNPRK1,E:\\ AZNKTNPR76等...
这是如何移动目录的示例:
Dim sSourcePath As String
Dim sDestPath As String
Dim sTextToFind As String
sSourcePath = "D:\Temp"
sDestPath = "D:\Temp1"
sTextToFind = "test"
For Each sDir In Directory.GetDirectories(sSourcePath, "*" & sTextToFind & "*")
Directory.Move(sDir, Path.Combine(sDestPath, Path.GetFileName(sDir)))
Next
为了复制文件夹中的所有文件,可以将循环更改为:
Dim sFullDestDir As String
sFullDestDir = Path.Combine(sDestPath, IO.Path.GetFileName(sFullSourceDir))
' Create the directory if it doesn't exist
If Not Directory.Exists(sFullDestDir) Then
Directory.CreateDirectory(sFullDestDir)
End If
' Copy the files in the directory
' If subfolders are to be copied, this logic can be turned into a recursive method.
For Each sFileName As String In Directory.GetFiles(sFullSourceDir)
File.Copy(sFileName, Path.Combine(sFullDestDir, IO.Path.GetFileName(sFileName)))
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.