如何删除" FolderName"来自 directoryPaths 数组的项目?不是来自路径,而是来自 directoryPaths 。
string[] directoryPaths = Directory.GetDirectories(@path);
答案 0 :(得分:2)
使用List,而不是数组。
var directoryPaths = Directory.GetDirectories((@path).ToList();
directoryPaths.Remove(FolderName);
答案 1 :(得分:2)
您可以通过查找要删除的元素(例如,在索引del
处)进行此更改,将 del
之后的所有元素向下移动一个index,然后通过调用Array.Resize
来调整数组大小:
int del = Array.IndexOf(directoryPaths, @path+"\\Desktop Files"); // Pick an index to delete
for (int i = del+1 ; i != directoryPaths.Length ; i++) {
directoryPaths[i-1] = directoryPaths[i];
}
Array.Resize(directoryPaths.Length-1);
答案 2 :(得分:1)
using System.Linq;
var paths = directoryPaths
.Where(p => p != folderName)
.ToArray();