PDA

View Full Version : بدست آوردن تعداد فایل با اسم خاص



rahimi.mohamad24
جمعه 20 مرداد 1391, 21:52 عصر
سلام
1-چطوری می تونم تعداد فایل هایی را که با یک نام خاص شروع می شوند و دارای یک پسوند خاص هستند را در یک فولدر بدست آورد؟

tooraj_azizi_1035
جمعه 20 مرداد 1391, 21:57 عصر
class FindFileByExtension
{
// This query will produce the full path for all .txt files
// under the specified folder including subfolders.
// It orders the list according to the file name.
static void Main()
{
string startFolder = @"c:\program files\Microsoft Visual Studio 9.0\";

// Take a snapshot of the file system.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);

// This method assumes that the application has discovery permissions
// for all folders under the specified path.
IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

//Create the query
IEnumerable<System.IO.FileInfo> fileQuery =
from file in fileList
where file.Extension == ".txt"
orderby file.Name
select file;

//Execute the query. This might write out a lot of files!
foreach (System.IO.FileInfo fi in fileQuery)
{
Console.WriteLine(fi.FullName);
}

// Create and execute a new query by using the previous
// query as a starting point. fileQuery is not
// executed again until the call to Last()
var newestFile =
(from file in fileQuery
orderby file.CreationTime
select new { file.FullName, file.CreationTime })
.Last();

Console.WriteLine("\r\nThe newest .txt file is {0}. Creation time: {1}",
newestFile.FullName, newestFile.CreationTime);

// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}

ali_habibi1384
جمعه 20 مرداد 1391, 23:46 عصر
پياده سازي با استفاده از Thread
برو حالشو ببر:
http://0.1.0.img98.net/out.php/i426772_search.jpg