如何做一个Directory.GetFiles
并排除名为“abc”和“xyz”的文件?Directory.GetFiles(strFolderPath)排除某些文件名VB.NET
基本上我有一个DIR,所有文件都存在,一组文件必须发送到一个部门,而“abc”和“xyz”文件需要发送到另一个部门?
目前,我这样做:
'Standard Documents
Dim strAttachments As List(Of String) = New List(Of String)
strAttachments.AddRange(Directory.GetFiles(GlobalVariables.strFolderPath))
我需要相同的功能,但不包括的文件,然后做如上类似的命令中包含的文件到另一个地址。
干杯,,
詹姆斯
UPDATE
Dim exclude = {"ATS_Declaration"}
Dim myFiles = From fn In Directory.EnumerateFiles(GlobalVariables.strFolderPath)
Where Not exclude.Contains(Path.GetFileNameWithoutExtension(fn), StringComparer.InvariantCultureIgnoreCase)
Dim strAttachments As List(Of String) = New List(Of String)(myFiles)
可能重复[从Directory.EnumerateFiles基于多个条件排除文件](http://stackoverflow.com/questions/27285113/exclude-files-from-directory-enumeratefiles-based-on-multiple-criteria) – Plutonix 2014-12-04 15:28:36
为什么不迭代strAttachments并在之后创建两个列表? – WeSt 2014-12-04 15:28:43