从folderbrowserdialog获取内容路径

编程入门 行业动态 更新时间:2024-10-14 04:29:14
本文介绍了从folderbrowserdialog获取内容路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何从folderbrowserdialog获取所选文件夹中的路径? 示例: 1)用户选择D:\ Content \Data 2)文件夹Data里面有一些文件和文件夹 3)我检查所有包含的文件在目录中,并希望将其复制到新目标。但是失败了 4)如何从所选文件夹中获取文件路径? 例如: D:\Content\Data\ABC.ai并获得ABC.ai仅 D:\Content\Data\Cfg.ini并获得Cfg。 ini只有 D:\ Content\Data\Debug\App.exe并且只获得Debug\App.exe D :\ Content \Data \Debug \DB.mdb并仅获取Debug\DB.mdb

Hi, How to get a path in a selected folder from folderbrowserdialog? Example: 1) User select D:\Content\Data 2) Inside folder "Data" there's contain some files and folder 3) I check all the files contains in the directory and want to copy it to new destination. But failed 4) How to get the file path from the selected folder? eg: "D:\Content\Data\ABC.ai" and get "ABC.ai" only "D:\Content\Data\Cfg.ini" and get "Cfg.ini" only "D:\Content\Data\Debug\App.exe" and get "Debug\App.exe" only "D:\Content\Data\Debug\DB.mdb" and get "Debug\DB.mdb" only

Assume Dim filename as String = 'Data from above'

因为目的地路径以\\user-pc\files给出。所以我想使用

Because the destination path is given as "\\user-pc\files".So I want to use

Assume Dim strDestinationFolderPath as String = 'Path from above'

因此复制的代码如下所示:

So the copied code will be as below

My.Computer.FileSystem.CopyDirectory(fileName, strDestinationFolderPath & "\" filename & , True)

推荐答案

我得到的东西: I just got the thing: Public Sub ProcessDirectory(ByVal targetDirectory As String) Dim f As New DirectoryInfo(targetDirectory) Dim dirs() As DirectoryInfo = f.GetDirectories() For Each d As DirectoryInfo In dirs Try My.Computer.FileSystem.CreateDirectory(strDestinationFolderPath & "\" & d.Name) txtevents.Text &= "Folder " & d.Name & " created" & Environment.NewLine Catch ex As Exception txtevents.Text &= ">> Error: Folder " & strDestinationFolderPath & "\" & d.Name & " failed to created" & Environment.NewLine End Try Next Dim fileEntries As String() = Directory.GetFiles(targetDirectory) Dim fileName As String For Each fileName In fileEntries Try Dim strNewFile As String = fileName.Replace(strSourceFolderPath & "\", "") My.Computer.FileSystem.CopyFile(fileName, strDestinationFolderPath & strNewFile, True) txtevents.Text &= "File " & fileName & " copied" & Environment.NewLine Catch ex As Exception txtevents.Text &= ">> Error: File " & fileName & " failed to copied" & Environment.NewLine End Try Next fileName Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory) Dim subdirectory As String For Each subdirectory In subdirectoryEntries ProcessDirectory(subdirectory) Next subdirectory End Sub

更多推荐

从folderbrowserdialog获取内容路径

本文发布于:2023-11-25 23:10:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   内容   folderbrowserdialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!