本文整理汇总了C#中System.IO.DirectoryInfo.Walk方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Walk方法的具体用法?C# DirectoryInfo.Walk怎么用?C# DirectoryInfo.Walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.Walk方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListCandidates
/// <summary>
/// Returns a list of entry point <see cref="Candidate"/>s in a directory.
/// </summary>
/// <param name="baseDirectory">The base directory to scan for entry points.</param>
public static List<Candidate> ListCandidates(DirectoryInfo baseDirectory)
{
var candidates = new List<Candidate>();
baseDirectory.Walk(fileAction: file =>
{
// Ignore uninstallers
if (file.Name.ContainsIgnoreCase("uninstall") || file.Name.ContainsIgnoreCase("unins0")) return;
var candidate = _candidateCreators.Select(x => x()).FirstOrDefault(x => x.Analyze(baseDirectory, file));
if (candidate != null) candidates.Add(candidate);
});
return candidates;
}
示例2: archiveExtractPage_Initialize
private void archiveExtractPage_Initialize(object sender, WizardPageInitEventArgs e)
{
_archive = (Archive)_feedBuilder.RetrievalMethod;
listBoxExtract.BeginUpdate();
listBoxExtract.Items.Clear();
var baseDirectory = new DirectoryInfo(_feedBuilder.TemporaryDirectory);
baseDirectory.Walk(dir => listBoxExtract.Items.Add(dir.RelativeTo(baseDirectory)));
listBoxExtract.SelectedItem = baseDirectory.WalkThroughPrefix().RelativeTo(baseDirectory);
listBoxExtract.EndUpdate();
}
示例3: buttonSearch_Click
private void buttonSearch_Click(object sender, EventArgs e)
{
DirectoryInfo searchDirectory;
try
{
searchDirectory = new DirectoryInfo(textFolder.Text);
}
#region Error handling
catch (ArgumentException ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
return;
}
#endregion
if (!searchDirectory.Exists)
{
Msg.Inform(this, "Directory does not exist.", MsgSeverity.Warn);
return;
}
Preferences.LastSearchDirectory = searchDirectory.FullName;
var resultSet = new ResultSet();
var checkedTags = tags.TreeView.CheckedEntries.Select(x => x.Name).ToList();
try
{
var handler = new GuiTaskHandler(this);
handler.RunTask(new SimpleTask("Searching", () =>
searchDirectory.Walk(fileAction: file =>
{
var fileTags = file.ReadTags();
if (checkedTags.All(fileTags.Contains)) resultSet.Add(file);
})));
resultSet.Show();
}
#region Error handling
catch (IOException ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
catch (UnauthorizedAccessException ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
catch (Win32Exception ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
#endregion
}
示例4: GetFilesToWrite
private string[] GetFilesToWrite()
{
var paths = new List<string>();
var source = new DirectoryInfo(Source);
source.Walk(fileAction: file => paths.Add(Path.Combine(Target, file.RelativeTo(source))));
return paths.ToArray();
}
示例5: Execute
/// <inheritdoc/>
protected override void Execute()
{
_source = new DirectoryInfo(SourcePath);
_destination = new DirectoryInfo(DestinationPath);
if (!_source.Exists) throw new DirectoryNotFoundException(Resources.SourceDirNotExist);
if (_destination.Exists)
{ // Fail if overwrite is off but the target directory already exists and contains elements
if (!Overwrite && _destination.GetFileSystemInfos().Length > 0)
throw new IOException(Resources.DestinationDirExist);
}
else _destination.Create();
State = TaskState.Header;
var sourceDirectories = new List<DirectoryInfo>();
var sourceFiles = new List<FileInfo>();
_source.Walk(sourceDirectories.Add, sourceFiles.Add);
UnitsTotal = sourceFiles.Sum(file => file.Length);
State = TaskState.Data;
CopyDirectories(sourceDirectories);
CopyFiles(sourceFiles);
if (PreserveDirectoryTimestamps)
CopyDirectoryTimestamps(sourceDirectories);
State = TaskState.Complete;
}