如何将文件复制到某些文件夹? [英] How copy file to some folders?

查看:91
本文介绍了如何将文件复制到某些文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文件复制到某些子文件夹

推荐答案

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.


这篇关于如何将文件复制到某些文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆