[VB.Net] OpenFileDialog多个文件 [英] [VB.Net] OpenFileDialog Multiple Files

查看:369
本文介绍了[VB.Net] OpenFileDialog多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我在VB.Net中有一个OpenFileDialog



现在我能够选择多个文件,并且所有作品都在那一面完美但我可以锻炼如果一个选择文件夹以使用它来递送thos目录和子目录中的文件。



因为我需要通过我的代码传递它。



Hi i have a OpenFileDialog In VB.Net

Now im able to select the multiple files and all works perfect in that side but i can workout how if a folder is selected to recurse thos files in thos directories and sub directories with It.

As i need to pass it through my code.

Dim files As String() = OpenFileDialog1.FileNames
Parallel.ForEach(files, Sub(currentFile)
   'Crypto.HashSum512.HashSum.FileToCheck Is for SHA512 HashSum. Crypto.HashSum512.HashSum.FileToCheck you pass the file path to the file/files you wish to check.
   Crypto.HashSum512.HashSum.FileToCheck = currentFile
   'Crypto.HashSum512.HashSum.ComputeHash.ToString Is for returning the hash value
   Dim ValueHash = Crypto.HashSum512.HashSum.ComputeHash
   Dim safedelegate As New SafeThreadedText(AddressOf ChangeUiOutput)
   Dim SafeThreadValueHash As String = currentFile.ToString & vbTab & ValueHash & vbCrLf
   WaitEvents.Set()
   Me.Invoke(safedelegate, SafeThreadValueHash)
   End Sub)





所以基本上我需要openfiledialog的帮助,当选择所有文件和文件夹来获取文件夹中的文件时。



谢谢您好好为我的问题提供任何提示或想法。



从非解决方案复制的其他信息

我需要选择文件或文件以及选择文件时选择的任何文件夹中的任何文件。



我不能使用OpenFileDialog以及FolderBrowseDialog相同的按钮和功能它是不切实际的,可能在设计方面不是很专业。



必须有一种方法可以做到否则没人会用VB.Net作为编程语言。



我花了两个多月的时间搜索和尝试各种各样的事情,我花了6个多月的时间来完成这个项目只是为了碰壁,其他一切都完成了我已经准备好了最后一件事,如果我找不到解决方案,那么我将不得不废弃整个项目并从头开始用一种新语言,Witch可能意味着所有的时间都是浪费。



我终于要求帮忙。



感谢任何可以提供帮助的人:)



So basically i need help with the openfiledialog when all files and folders are selected to get the files in the folders as well.

Thank you kindly for any tips hints or ideas for my issue.

additional information copied from non solution below
I need to select files or a file and any files in any folder that is selected when selecting the files.

I can't have an OpenFileDialog as well as FolderBrowseDialog on the same button and function it would be impractical and probably not very professional in design terms.

There has to be a way surely it can be done otherwise no one would use VB.Net as a programming language.

I have spent over 2 months searching and trying all sorts of things, I have spent over 6 months working on this program only to hit a wall, Everything else it complete ready to go its just this one last thing and if i can't find a solution then i will have to scrap the entire project and start from scratch with a new language, Witch could mean all that time was a waste.

I finally am asking around for help.

Thank you to anyone who can help :)

推荐答案

OpenFileDialog不会让你选择一个文件夹 - 只有一个或多个文件。

要选择文件夹,你需要 FolderBrowserDialog [ ^ ]和Directory.GetFiles [ ^ ],SearchOption设置为AllDirectories
OpenFileDialog won't let you select a folder - only a file or files.
To select folders, you need the FolderBrowserDialog[^] and Directory.GetFiles[^] with the SearchOption set to AllDirectories


解决方案1完全有效,你似乎坚持我必须使用OpenFileDialog的想法。实际上,您需要打开给定文件夹及其子文件夹中的所有文件(无论它们是否具有相同的扩展名)。

让我尝试将其转换为VB(这不是我最喜欢的)你已经拥有的东西:

Solution 1 is perfectly valid, it seems you are stuck on the idea 'I have to use an OpenFileDialog'. In fact, you need to open all files (whether they have the same extension or not) in a given folder and its subfolders.
Let me try to translate that to VB (that's not my favorite) according to what you already have:
Dim rootPath As String

Using dialog As New FolderBrowserDialog()
   If (dialog.DialogResult = DialogResult.OK)
      rootPath = dialog.SelectedPath
   End If
End Using

If Not String.IsNullOrEmpty(rootPath)
   Dim files As String() = Directory.GetFiles(rootPath, "*.*", SearchOption.AllDirectories)
   ' From here I did not touch the code...
   Parallel.ForEach(files, Sub(currentFile)
      'Crypto.HashSum512.HashSum.FileToCheck Is for SHA512 HashSum.    Crypto.HashSum512.HashSum.FileToCheck you pass the file path to the file/files you wish to check.
      Crypto.HashSum512.HashSum.FileToCheck = currentFile
      'Crypto.HashSum512.HashSum.ComputeHash.ToString Is for returning the hash value
      Dim ValueHash = Crypto.HashSum512.HashSum.ComputeHash
      Dim safedelegate As New SafeThreadedText(AddressOf ChangeUiOutput)
      Dim SafeThreadValueHash As String = currentFile.ToString & vbTab & ValueHash & vbCrLf
      WaitEvents.Set()
      Me.Invoke(safedelegate, SafeThreadValueHash)
      End Sub)
End If ' ... except here





如果你只需要处理根文件夹中所有文件的子集,你可以使用另一个参数而不是< GetFiles()调用中code> *。* 。



继续尝试;因为这样一个微不足道的问题,从头开始重新启动一个项目真是太可惜了。

至于'从头开始用新语言':你不要真的认为这是一个语言问题,对吗?



If you have to process only a subset of all the files in the root folder, you can use another parameter than *.* in the GetFiles() call.

Keep trying; it would be such a pity to restart a project from scratch just because of such a trivial problem.
As for 'start from scratch with a new language': you don't really think it's a language problem, do you?


你好Menon



谢谢你的回复但不是我的解决方案寻找。



我需要选择文件或文件以及选择文件时选择的任何文件夹中的任何文件。



我不能在同一个按钮和功能上使用OpenFileDialog和FolderBrowseDialog,这在设计方面可能不太实用,可能也不是很专业。



必须有一种方法可以做到,否则没有人会使用VB.Net作为编程语言。



我花了2个多月的时间搜索并尝试各种各样的事情,我已经花了6个多月的时间来完成这个项目只是为了碰壁,其他一切都已经完成了o它只是最后一件事,如果我找不到解决方案,那么我将不得不废弃整个项目并从头开始用一种新语言,Witch可能意味着所有的时间都是浪费。



我终于要求帮忙。



感谢任何可以提供帮助的人:)
Hi Menon

thank you for your reply but not the solution im looking for.

I need to select files or a file and any files in any folder that is selected when selecting the files.

I can't have an OpenFileDialog as well as FolderBrowseDialog on the same button and function it would be impractical and probably not very professional in design terms.

There has to be a way surely it can be done otherwise no one would use VB.Net as a programming language.

I have spent over 2 months searching and trying all sorts of things, I have spent over 6 months working on this program only to hit a wall, Everything else it complete ready to go its just this one last thing and if i can't find a solution then i will have to scrap the entire project and start from scratch with a new language, Witch could mean all that time was a waste.

I finally am asking around for help.

Thank you to anyone who can help :)


这篇关于[VB.Net] OpenFileDialog多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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