如何将文件复制到某些文件夹?
问题描述:
如何将文件复制到某些子文件夹?
答
与vb.net如何将文件从一个目录复制到另一个目录如果该文件夹不存在,则创建文件夹 [ ^ ]您将此问题作为解决方案发布
此代码片段将列出C:\Develop的所有子文件夹(替换您需要的任何文件夹)
Exactly the same way as the solution to vb.net how to copy file from one Directory to another directory by create the folder if that folder is not exists[^] where you posted this question as a solution
This code snippet will list all of the sub-folders of C:\Develop (substitute whichever folder you need for that)
Dim dr As String() = System.IO.Directory.GetDirectories("C:\Develop")
For Each s As String In dr
Debug.Print(s) 'Replace this bit with your file copy
Next
这基本上是我的整个测试表格
This is essentially my entire test form
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dr As String() = Directory.GetDirectories("d:\Gry\OMSI 2\Vehicles")
Dim filter As String = "*.BUS" 'case CAPS or lower doesn't matter
For Each s As String In dr
Dim di As New DirectoryInfo(s) 'Get information about the sub-folder
Dim fi As FileInfo() = di.GetFiles(filter) 'Look for the files you want consider
If fi.GetUpperBound(0) >= 0 Then
Debug.Print("Found folder " + s + " containing file like " + filter)
End If
Next
End Sub
End Class
NB - 如果您的子文件夹有自己的子文件夹,并且您/不想查看这些子文件夹中的* .bus那么你可以使用
NB - If your sub-folders have sub-folders of their own, and you do/don't want to look in those sub-folders for *.bus then you can use
Dim fi As FileInfo() = di.GetFiles(filter, SearchOption.TopDirectoryOnly)
和
Dim fi As FileInfo() = di.GetFiles(filter, SearchOption.AllDirectories)
准确指定你想要的东西。
to specify exactly what you want.