如何做一個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