一个文件夹拷贝的实现(VB.net)

' isOrNot 判断是否要拷贝

'fromFile 要拷贝的文件

'toPath 指定文件存放的位置

 Private Function CopyFile(ByVal isOrNot As Boolean, ByVal fromFile As String, ByVal toPath As String)
        If isOrNot = True Then
            Dim strFolderName As String = fromFile.Substring(fromFile.LastIndexOf("/") + 1, fromFile.Length - fromFile.LastIndexOf("/") - 1)
            If Not Directory.Exists(toPath & "/" & strFolderName) Then
                Directory.CreateDirectory(toPath & "/" & strFolderName)
            End If
            Dim strFiles As String() = Directory.GetFiles(fromFile)

            For i As Integer = 0 To strFiles.Length - 1
                Dim fileName As String = strFiles(i).Substring(strFiles(i).LastIndexOf("/") + 1, strFiles(i).Length - strFiles(i).LastIndexOf("/") - 1)
                File.Copy(strFiles(i), toPath & "/" & strFolderName & "/" & fileName, True)
            Next
            Dim dirInfo As DirectoryInfo = New DirectoryInfo(fromFile)
            Dim ziPath As DirectoryInfo() = dirInfo.GetDirectories()
            For j As Integer = 0 To ziPath.Length - 1
                Dim strZiPath As String = fromFile & "/" & ziPath(j).ToString()
                CopyFile(True, strZiPath, toPath & "/" & strFolderName)
            Next
        End If
    End Function 

第一次写技术性文章,有不对的地方希望大家来指正!谢谢!

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值