本文整理汇总了C#中IDirectory.GetFiles方法的典型用法代码示例。如果您正苦于以下问题:C# IDirectory.GetFiles方法的具体用法?C# IDirectory.GetFiles怎么用?C# IDirectory.GetFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectory
的用法示例。
在下文中一共展示了IDirectory.GetFiles方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnFileRequested
/// <summary>
/// Called when the file is requested by a client.
/// </summary>
/// <param name="request">The <see cref="HttpRequest"/> requesting the file.</param>
/// <param name="directory">The <see cref="IDirectory"/> of the parent directory.</param>
public void OnFileRequested(HttpRequest request, IDirectory directory)
{
ICollection dirs;
ICollection files;
try
{
dirs = directory.GetDirectories();
files = directory.GetFiles();
}
catch(UnauthorizedAccessException)
{
throw new HttpRequestException("403");
}
request.Response.BeginChunkedOutput();
StreamWriter writer = new StreamWriter(request.Response.ResponseContent);
writer.WriteLine("<html>");
writer.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
writer.WriteLine("<head><title>Index of " + HttpWebServer.GetDirectoryPath(directory) + "</title></head>");
writer.WriteLine("<body>");
PrintBody(writer, request, directory, dirs, files);
writer.WriteLine("<hr>" + request.Server.ServerName);
writer.WriteLine("</body></html>");
writer.WriteLine("</body>");
writer.WriteLine("</html>");
writer.Flush();
}
示例2: FindFiles
/// <summary>
/// Searches the given directory for files matching the search parameters of this object.
/// </summary>
/// <param name="directory">The directory to search.</param>
/// <returns>A collection of files.</returns>
public IEnumerable<IFile> FindFiles(IDirectory directory)
{
return from pattern in GetFilePatterns()
from file in directory.GetFiles(pattern, SearchOption)
where IsAssetFile(file)
select file;
}
示例3: FindFiles
/// <summary>
/// Searches the given directory for files matching the search parameters of this object.
/// </summary>
/// <param name="directory">The directory to search.</param>
/// <returns>A collection of files.</returns>
public IEnumerable<IFile> FindFiles(IDirectory directory)
{
var files =
from pattern in GetFilePatterns()
from file in directory.GetFiles(pattern, SearchOption)
where IsAssetFile(file)
select file;
return RemoveMinifiedFilesWhereNonMinExist(files);
}
示例4: Run
private static void Run(IDirectory directory)
{
foreach (var file in directory.GetFiles())
{
if (file.Name.EndsWith(".aspx", StringComparison.CurrentCultureIgnoreCase)
|| file.Name.EndsWith(".ascx", StringComparison.CurrentCultureIgnoreCase))
{
ReplaceLegacyControlTags(file);
}
}
foreach (var dir in directory.GetDirectories())
{
Run(dir);
}
}
示例5: Run
private static void Run(IDirectory directory)
{
foreach (var file in directory.GetFiles())
{
if (file.Name.EndsWith(".aspx", StringComparison.CurrentCultureIgnoreCase)
|| file.Name.EndsWith(".ascx", StringComparison.CurrentCultureIgnoreCase))
{
var contents = file.Contents;
string newContent = GetUpgradedSkinFileContents(contents);
if (contents != newContent)
{
using (var stream = new StreamWriter(file.OpenWrite()))
{
stream.Write(newContent);
stream.Close();
}
}
}
}
foreach (var dir in directory.GetDirectories())
{
Run(dir);
}
}
示例6: FileCount
/// <summary>
/// Performs a recursive FileCount of the given directory (and it's descendents)
/// </summary>
/// <param name="directory"></param>
/// <returns></returns>
private int FileCount(IDirectory directory)
{
int count = directory.GetFiles().Count;
// Iterate the child directories
foreach (IDirectory childDirectory in directory.GetDirectories())
{
count += FileCount(childDirectory);
}
return count;
}
示例7: PerformCleanup
public static void PerformCleanup(IDirectory dir, string path, IFile file)
{
try
{
foreach(var v in dir.GetFiles(path).Where(a => a.Contains("tmp")))
file.Delete(v);
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
//best effort.
}
}
示例8: createDirectoriesAndFiles
private void createDirectoriesAndFiles(IDirectory sourceDirectory, IDirectory destinationDirectory, string name)
{
IDirectory destDir;
if (name == null)
destDir = destinationDirectory.CreateSubdirectory(sourceDirectory.Name);
else
destDir = destinationDirectory.CreateSubdirectory(name);
foreach (var dir in sourceDirectory.GetDirectories())
{
createDirectoriesAndFiles(dir, destDir, null);
}
foreach (var file in sourceDirectory.GetFiles())
{
destDir.CreateFile(file);
}
}
示例9: findManifest
private List<LocalTempList> findManifest(IDirectory rootDir)
{
var tempLocalList = new List<LocalTempList>();
//"Manifest.xml"
var file = rootDir.GetFiles(_manifestFileName).FirstOrDefault();
if (file != null)
{
//Create the temp manifest file
var localFileName = _localTempStorage.SaveManifest(file.GetBytes());
tempLocalList.Add(new LocalTempList() { LocalPath = localFileName, PackageStorePath = file.FullName });
Console.WriteLine("Found app at path: {0}", file.FullName);
}
else
{
foreach (var dir in rootDir.GetDirectories())
{
tempLocalList.AddRange(findManifest(dir));
}
}
return tempLocalList;
}