请帮助选择案例陈述 [英] Help With Select Case Statement Please

查看:98
本文介绍了请帮助选择案例陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前曾问过有关搜索多种文件类型的问题.给出的解决方案建议我为每个要搜索的文件扩展类型的每个语句添加一个新语句,然后将该值返回给getfiles.我的问题是我要搜索40或45个文件类型,因此为每个语句添加40或45将导致很大的性能问题.

我可以使用select case语句向其中添加所有文件扩展名吗?然后我可以以某种方式致电此案吗?是这样吗?


预先感谢你们,让我们摇滚!

I have previously asked about searching for multiple file types. The solution that was given suggests that I add a new for each statement for every file extention type that I wish to search for and then to return the value to getfiles. My problem is that I have 40 or 45 file types I wish to search for so adding 40 or 45 for each statements will have a big performance issue.

Am I able to use a select case statement to add all the file extensions to? and then will i be able to somehow call the case? is that how it works?


Thank you in advance you guys rock!

推荐答案

否.没有要放入选择案例语句的案例.与假设此数量相当大的文件总数相比,大量的文件扩展名(40-45?)根本不是性能的重要因素.

不同文件扩展名的数量并不是很大,与性能无关.唯一实际的因素是找到的文件名总数.假设您将创建一个双循环:外循环将遍历您需要的一组扩展名(例如,每个代表文件掩码的字符串数组)并调用System.IO.DirectoryGetFiles(String, String, SearchOption),内部循环将运行遍历为每个文件掩码找到的所有文件.请参阅 http://msdn.microsoft.com/en-us/library/system.io .directory.aspx [ ^ ].

别忘了,使用文件掩码有一些警告.在此处使用解决方案进行描述: Directory.Get.Files搜索模式问题 [ ^ ].

—SA
No. There are no cases to put in select case statement. And big number of file extensions (40-45?) is not a big factor of performance at all compared to the total number of files found assuming this number is considerable.

This number of different file extension is not so big to be relevant to performance at all; the only real factor is a total number of file names found. Let''s say, you will make a double loop: outer loop will run through a set of extensions you need (for example, an array of strings each representing a file mask) and call to System.IO.DirectoryGetFiles(String, String, SearchOption), and internal loop will run through all the files found for each file mask. See http://msdn.microsoft.com/en-us/library/system.io.directory.aspx[^].

Don''t forget, there is a caveat in using a file mask. It is described with the solution here: Directory.Get.Files search pattern problem[^].

—SA


您可以执行类似的操作,但是它的性能还取决于该目录中无用文件的数量,这些文件不被视为基于在扩展名上.
You can do something like this, but it''s performance also depends on number of useless files in that directory which are not to be considered based on extension.
Dim filePaths() As String = System.IO.Directory.GetFiles("c:\MyDir\", "*.*", SearchOption.AllDirectories)
For Each filepath As String In filePaths
  Select Case IO.Path.GetExtension(filepath).ToLower
    Case "bmp"
    Case "jpg"
      '...
    Case Else
  End Select
Next


这篇关于请帮助选择案例陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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