我的文件夹包含超过100个zip文件。我想从文件夹中选择随机6 zip文件。从文件夹中选择随机文件
我尝试:
DirectoryInfo test= new DirectoryInfo(@"C:\test").GetFiles();
foreach (FileInfo file in test.GetFiles())
{
Random R = new Random(); //try to apply random logic but fail.
if (file.Extension == ".zip")
{
string a="";
for (int ListTemplate = 0; ListTemplate < 6; ListTemplate++)
{
a += file.FullName; //Want to choose random 6 files.
}
}
}
有什么办法来帮忙做this.Thanks。
可能重复的[从目录中选择随机文件](http://stackoverflow.com/questions/742685/select-random-file-from-directory) – Stasel
你不随意使用随机,随便选一个随机0和'GetFiles()。Count - 1'之间的数字...(不需要foreach) – Sayse
我搜索并找到该链接,但它选择了所有文件。不重复。 –