如何从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获取内容路径
发布评论