या यह अपने आप करते हैं,
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal static extern IntPtr FindFirstFile(string lpFileName, out
WIN32_FIND_DATA lpFindFileData);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal static extern bool FindNextFile(IntPtr hFindFile, out
WIN32_FIND_DATA lpFindFileData);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool FindClose(IntPtr hFindFile);
// Assume dirName passed in is already prefixed with \\?\
public static IEnumerable<string> EnumerateEntries(string directory)
{
WIN32_FIND_DATA findData;
IntPtr findHandle = FindFirstFile(dirName + @"\*", out findData);
try
{
if (findHandle != INVALID_HANDLE_VALUE)
{
bool found;
do
{
string currentFileName = findData.cFileName;
// if this is a directory, find its contents
if (((int)findData.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY) != 0)
{
if (currentFileName != "." && currentFileName != "..")
{
foreach(var child in FindFilesAndDirs(
Path.Combine(dirName, currentFileName))
{
yield return child;
}
}
}
yield return Path.Combine(dirName, currentFileName);
// find next
found = FindNextFile(findHandle, out findData);
}
while (found);
}
}
finally
{
// close the find handle
FindClose(findHandle);
}
}
मैं इस कोड सत्यापित नहीं किया है और स्पष्ट रूप से नहीं सभी प्रकार परिभाषित कर रहे हैं, लेकिन यह सही दिशा में हमें इंगित करना चाहिए।
Downvoter देखभाल टिप्पणी करने के लिए एक बाहरी पुस्तकालय या पी का उपयोग किए बिना एक headstart दे देंगे लागू ..? – soandos
पूरे फाइल सिस्टम स्कैन करने के लिए सबसे अच्छा अभ्यास व्यक्तिगत संदर्भ स्विच लगता है - .NET में, शायद यह एक नए धागे की तरह दिखने वाला है - कम से कम पहले स्तर के लिए यदि दूसरा या तीसरा नहीं है। यही है, प्रत्येक रूट फ़ोल्डर के लिए एक थ्रेड स्पिन करें, उस धागे में एक बार निर्देशिका बदलें, फिर आगे बढ़ें। यदि आप चालाक हैं, तो आप केवल तभी स्प्रेड कर सकते हैं जब पथ की लंबाई सीमा पार हो जाती है, फिर वहां निर्देशिका बदलें और प्रभावी ढंग से अपनी पथ की लंबाई सहिष्णुता को रीसेट करें। – ssamuel
कैसे करें: एक निर्देशिका वृक्ष के माध्यम से Iterate (सी # प्रोग्रामिंग गाइड) http://msdn.microsoft.com/en-us/library/bb513869.aspx – JamieSee