本文整理汇总了C#中IFileSystem.GetFilesInDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.GetFilesInDirectory方法的具体用法?C# IFileSystem.GetFilesInDirectory怎么用?C# IFileSystem.GetFilesInDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.GetFilesInDirectory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateFileList
/// <summary>
/// Generate the list of files to include in the package.
/// </summary>
/// <param name="result">The build result.</param>
/// <param name="fileSystem">The file system.</param>
/// <returns>A list of all the files to be included.</returns>
/// <remarks>
/// This method uses custom logic for handling "**"
/// </remarks>
private List<string> GenerateFileList(IIntegrationResult result, IFileSystem fileSystem)
{
var fileList = new List<string>();
var allDirsWildcard = Path.DirectorySeparatorChar + "**" + Path.DirectorySeparatorChar;
// Handle any wildcard characters
if (this.SourceFile.Contains("*") || this.SourceFile.Contains("?"))
{
var possibilities = new List<string>();
var actualPath = Path.IsPathRooted(this.SourceFile) ? this.SourceFile : result.BaseFromWorkingDirectory(this.SourceFile);
// Check for **, if it exists, then split the search pattern and use the second half to find all
// matching files
if (actualPath.Contains(allDirsWildcard))
{
var position = actualPath.IndexOf(allDirsWildcard);
var path = actualPath.Substring(0, position);
var pattern = actualPath.Substring(position + 4);
possibilities.AddRange(fileSystem.GetFilesInDirectory(path, pattern, SearchOption.AllDirectories));
}
else
{
// Otherwise, just use the plain ordinary search pattern
var position = actualPath.IndexOfAny(new char[] { '*', '?' });
position = actualPath.LastIndexOf(Path.DirectorySeparatorChar, position);
var path = actualPath.Substring(0, position);
var pattern = actualPath.Substring(position + 1);
possibilities.AddRange(fileSystem.GetFilesInDirectory(path, pattern, SearchOption.TopDirectoryOnly));
}
// The current list of files is just a set of possibilities, now need to check that they completely
// match the search criteria and they have not already been added.
foreach (var possibility in possibilities)
{
if (!fileList.Contains(possibility))
{
if (PathUtils.MatchPath(actualPath, possibility, false))
{
fileList.Add(possibility);
}
}
}
}
else
{
// Make sure the file is rooted
string actualPath = Path.IsPathRooted(this.SourceFile) ? this.SourceFile : result.BaseFromWorkingDirectory(this.SourceFile);
// Only add it to the list if it doesn't already exist
if (!fileList.Contains(actualPath))
{
fileList.Add(actualPath);
}
}
return fileList;
}
示例2: CopyFromIndex
private void CopyFromIndex(
string indexFile,
string targetFolder,
IFileSystem fileSystem,
ILogger logger,
IIntegrationResult result)
{
var basePath = Path.GetDirectoryName(indexFile);
using (var reader = fileSystem.Load(indexFile))
{
XDocument document = null;
try
{
document = XDocument.Load(reader);
}
catch (Exception error)
{
throw new CruiseControlException(
"Unable to load index file - " + error.Message ?? string.Empty,
error);
}
var rootEl = document.Element("ReportResources");
if (rootEl == null)
{
throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
}
var files = new List<string>();
foreach (var fileEl in rootEl.Elements("File"))
{
var fullPath = fileEl.Value;
if (!Path.IsPathRooted(fullPath))
{
fullPath = Path.Combine(basePath, fileEl.Value);
}
files.Add(fullPath);
}
foreach (var folder in rootEl.Elements("Directory"))
{
var fullPath = folder.Value;
if (!Path.IsPathRooted(fullPath))
{
fullPath = Path.Combine(basePath, fullPath);
}
files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
}
var baseLength = basePath.Length;
foreach (var file in files)
{
logger.Info("Copying file '{0}' to '{1}'", file, targetFolder);
var targetFile = file.StartsWith(basePath) ?
file.Substring(baseLength) :
Path.GetFileName(file);
result.BuildProgressInformation.AddTaskInformation(
string.Format(CultureInfo.CurrentCulture, "Copying file '{0}' to '{1}'", targetFile, targetFolder));
fileSystem.Copy(file, Path.Combine(targetFolder, targetFile));
}
}
}