当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.Walk方法代码示例

本文整理汇总了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;
        }
开发者ID:0install,项目名称:0install-win,代码行数:17,代码来源:Detection.cs

示例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();
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:13,代码来源:NewFeedWizard.cs

示例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
        }
开发者ID:nano-byte,项目名称:LightTag,代码行数:50,代码来源:SearchForm.cs

示例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();
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:9,代码来源:UpdateProcess.cs

示例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;
        }
开发者ID:nano-byte,项目名称:common,代码行数:26,代码来源:CopyDirectory.cs


注:本文中的System.IO.DirectoryInfo.Walk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。