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


C# DirectoryInfo.ToList方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.ToList方法的具体用法?C# DirectoryInfo.ToList怎么用?C# DirectoryInfo.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.ToList方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WritesAStreamAsync

        public async Task WritesAStreamAsync()
        {
            const string testoutputfilename = "test";
            string dir =  Config.GetDefaultDownloadDirectory();
            var files = new DirectoryInfo(dir).GetFiles().Where(n => n.Name == testoutputfilename + ".zip");
            var fileInfos = files as IList<FileInfo> ?? files.ToList();
            if (fileInfos.Any())
            {
                foreach (var file in fileInfos)
                {
                    File.Delete(file.FullName);
                }
            }
            FileInfo spyfile = new FileInfo(dir + @"\SPY_Companies.csv");

            AllDataDownloader dl = new AllDataDownloader(spyfile, null)
            {
                ZipOutput = true
            };
            await dl.WriteStreamAsync(DateTime.Now, "Test Data", dir, testoutputfilename);

            files = new DirectoryInfo(dir).GetFiles().Where(n => n.Name == testoutputfilename + ".zip");

            Assert.IsTrue(files.Any());
        }
开发者ID:bizcad,项目名称:MarketData,代码行数:25,代码来源:AllDataDownloaderTests.cs

示例2: RenameAllFiles

        public void RenameAllFiles(Func<string, string> nextSeedGenerator)
        {
            if(!Directory.Exists(BasePath))
            {
                throw new DirectoryNotFoundException();
            }

            var files = new DirectoryInfo(BasePath).GetFiles().OrderBy(x => x.CreationTimeUtc);
            string seed = null;

            files.ToList().ForEach(file =>
            {
                seed = nextSeedGenerator(seed);
                var newFilename = CreateFileName(file, seed);

                if(File.Exists(newFilename))
                {
                    var tempFileName = CreateFileName(file, Guid.NewGuid().ToString());
                    File.Move(newFilename, tempFileName);
                }

                File.Move(
                    file.FullName,
                    newFilename);
            });
        }
开发者ID:jacan,项目名称:FolderBulk,代码行数:26,代码来源:FileRename.cs

示例3: Initialize

 public void Initialize()
 {
     if(originalPathOfDlls != cleanCopyOfDllsLocation)
     {
         if (Directory.Exists(cleanCopyOfDllsLocation)) Directory.Delete(cleanCopyOfDllsLocation, true);
         Directory.CreateDirectory(cleanCopyOfDllsLocation);
         FileInfo[] allDlls = new DirectoryInfo(originalPathOfDlls).GetFiles("*.dll", SearchOption.AllDirectories);
         allDlls.ToList().ForEach(CopyToCleanCopyLocation);
     }
 }
开发者ID:LSudarshan,项目名称:SilverlightProfiler,代码行数:10,代码来源:Project.cs

示例4: Accept

 public void Accept(CodeVisitor visitor)
 {
     FileInfo[] allDlls = new DirectoryInfo(cleanCopyOfDllsLocation).GetFiles("*.dll", SearchOption.AllDirectories);
     List<FileInfo> files = allDlls.ToList().FindAll(MatchesPattern).ToList();
     var assemblies =
         new List<AssemblyDefinition>(files.Select(file => AssemblyFactory.GetAssembly(Path.Combine(cleanCopyOfDllsLocation, file.Name))));
     foreach (AssemblyDefinition assembly in assemblies)
     {
         ProcessAssembly(visitor, assembly);
     }
 }
开发者ID:LSudarshan,项目名称:SilverlightProfiler,代码行数:11,代码来源:Project.cs

示例5: Main

        static void Main(string[] args)
        {
            var path = @"D:\dev\EntityFramework";

            var excluded = new[] { @"\obj\Debug", @"\bin\Debug", @"\Properties" };
            Func<string, bool> isIncluded = (name) => excluded.All(e => !name.Contains(e));
            Func<DirectoryInfo, bool> witoutFiles = (di) => !di.GetFiles().Any();
            Func<DirectoryInfo, bool> witoutSubDir = (di) => !di.GetDirectories().Any();

            var dirs = new DirectoryInfo(path)
                .GetDirectories("*", SearchOption.AllDirectories)
                .Where(witoutFiles)
                .Where(witoutSubDir)
                .Select(di => di.FullName)
                .Where(isIncluded);

            dirs.ToList().ForEach(Console.WriteLine);
        }
开发者ID:gammja,项目名称:EFF,代码行数:18,代码来源:Program.cs

示例6: _bgwUpdater_DoWork

        void _bgwUpdater_DoWork(object sender, DoWorkEventArgs e)
        {
            Logger.LogDisp.NewMessage(LogType.Info, "Started player DB update...");
            var lastModTime = (DateTime)e.Argument;
            var len = _db.AccPath.Length + 12;

            if (!Directory.Exists(_db.AccPath))
            {
                Logger.LogDisp.NewMessage(LogType.Error,"Can't find FL PlayerDB!");
                _areReadyToClose.Set();
                return;
            }

            if (StateChanged != null)
                StateChanged(DBStates.UpdatingFormFiles);

            // find all the newer savefiles, get the directory path, get unique directories
            // LINQ magic ;)
            var accDirs =
                new DirectoryInfo(_db.AccPath).GetFiles("??-????????.fl", SearchOption.AllDirectories)
                    .Where(d => d.LastWriteTime > lastModTime)
                    .Select(w => w.FullName.Substring(0, len))
                    .Distinct();

            // add there all the directories whose content had changed (new\del accounts, bans etc)
            accDirs = accDirs.Union(
                new DirectoryInfo(_db.AccPath).GetDirectories("??-????????")
                .Where(w => w.LastWriteTime > lastModTime)
                .Select(w => w.FullName));

            var enumerable = accDirs as IList<string> ?? accDirs.ToList();

            Logger.LogDisp.NewMessage(LogType.Info,
                "Update: found " + enumerable.Count() + " changed accounts.");

            if (StateChanged != null)
                StateChanged(DBStates.Updating);

            var i = 0;
            var count = enumerable.Count;

            // rescan stuff
            foreach (var accDir in enumerable)
            {
                if (_bgwUpdater.CancellationPending)
                {
                    _areReadyToClose.Set();
                    Logger.LogDisp.NewMessage(LogType.Info,"Update aborted.");
                    e.Cancel = true;
                    return;
                }
                LoadAccountDirectory(accDir);
                _bgwUpdater.ReportProgress(
                    (int)(
                    ((double)i / count)
                    * 100
                    ), _db.Queue.Count
                    );
                i++;
            }
            _areReadyToClose.Set();
            Logger.LogDisp.NewMessage(LogType.Info, "Player DB update finished.");
        }
开发者ID:utrack,项目名称:FLAccountDB,代码行数:63,代码来源:Scanner.cs

示例7: DirectoryEntry

        /*private void ExplorerTv_Loaded(object sender, RoutedEventArgs e)
        {
            //add local network computers as root nodes
            DirectoryEntry root = new DirectoryEntry("WinNT:");
            foreach (DirectoryEntry computers in root.Children)
            {
                foreach (DirectoryEntry computer in computers.Children)
                {
                    if (computer.Name != "CLEMENT" && computer.Name != "Schema")
                    {
                        ExplorerTvItem networkComputer = new ExplorerTvItem();
                        networkComputer.TV.Header = computer.Name;
                        networkComputer.ItemType = ExplorerTvItem.NodeType.Computer;
                        networkComputer.IsExpanded = true;
                        ((TreeView)sender).Items.Add(networkComputer);

                        //string _tempstring = @"\\WORKGROUP\" + computer.Name + "\\share";
                        //Debug.WriteLine(@"\\WORKGROUP\" + computer.Name + "\share");
                        //var folders = Directory.GetDirectories(@"\\WORKGROUP\" + computer.Name + "\\share");
                        //foreach (var dir in folders)
                        //{
                        //    ExplorerTvItem folder = new ExplorerTvItem();
                        //    folder.Header = dir.ToString();
                        //    //folder.Tag = dir.FullName;
                        //    folder.ItemType = ExplorerTvItem.NodeType.Folder;
                        //    networkComputer.Items.Add(folder);
                        //}


                    }
                }
            }
        }*/

        // Dynamically fill the treview
        private void Folder_Expanded(object sender, RoutedEventArgs e)
        {
            ExplorerTvItem item = (ExplorerTvItem)sender;

            if (item.Items.Count == 1 && item.Items[0] == dummyNode)
            {
                item.Items.Clear();
                try
                {
                    // create the unhidden subfolder list
                    var directory = new DirectoryInfo(item.Tag.ToString()).GetDirectories().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);

                    // add the list the the expanded item
                    foreach (var dir in directory)
                    {
                        ExplorerTvItem folder = new ExplorerTvItem();
                        folder.Header = dir.ToString();
                        folder.Tag = dir.FullName;
                        folder.ItemType = ExplorerTvItem.NodeType.Folder;
                        item.Items.Add(folder);
                    }

                    // check if folders in the list contains visible subfolders to add them a dummynode
                    foreach (ExplorerTvItem folder in item.Items)
                    {
                        var subDir = new DirectoryInfo(folder.Tag.ToString()).GetDirectories().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);

                        if ((subDir.ToList()).Count > 0)
                        {
                            folder.Items.Add(dummyNode);
                            folder.Expanded += new RoutedEventHandler(Folder_Expanded);
                        }
                    }

                }

                catch (Exception) { }

            }



        }
开发者ID:Sugz,项目名称:CSharp,代码行数:78,代码来源:MainWindow.xaml.cs

示例8: Scan

            /// <summary>
            /// Scans the given path for image files and creates a hash for every element found.
            /// </summary>
            /// <param name="path">The directory to search through.</param>
            /// <param name="checkSubdirs">Include subdirectories?</param>
            /// <param name="minDate">Ignore files older than this date.</param>
            /// <returns>Returns a dictionary with the FileInfo-object of the file as key and its hash as value.</returns>
            private Dictionary<FileInfo, ulong> Scan(string path, bool checkSubdirs, DateTime minDate)
            {
                #region Scan subdirs or not
		            SearchOption __options;
                    if (checkSubdirs) __options = SearchOption.AllDirectories;
                    else __options = SearchOption.TopDirectoryOnly;
	            #endregion
                
                //Get all files
                var __files = new DirectoryInfo(path).GetFiles(new string[] { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp" }, __options).ToList();

                #region Filter according to a given date
                    if (minDate != null)
                        __files = __files.Where(f => DateTime.Compare(f.LastWriteTime, minDate) >= 0).ToList();
                #endregion

                State.Max = __files.Count;

                //todo: Because this is a parallel operation, the ConcurrentDictionary class is used instead of the standard Dictionary (which is not thread-safe) 
                //Critical issue, because doing this parallel saves a huge amount of time
                //var __images = new ConcurrentDictionary<FileInfo, ulong>();
                //__files.AsParallel().ForAll((f) => 
                var __images = new Dictionary<FileInfo, ulong>();
                __files.ToList().ForEach((f) => 
                {
                    //Calling the respective overridden method to create a hash (the case where the key already exists can't happen, so it's not implemented properly)
                    __images.Add(f, GetHash(f.FullName));
                    //Update the State to give information about the current image
                    State.Current = f.Name;
                    State.Count = __files.IndexOf(f) + 1;
                });
                return __images;
            }
开发者ID:Sekagra,项目名称:Doppelganger,代码行数:40,代码来源:ImageFinderBase.cs

示例9: getAllFiles

        /// <summary>
        /// Gets all files from the specified folder
        /// </summary>
        /// <param name="folder">which folder</param>
        /// <param name="order">sort order</param>
        /// <returns>list of all files</returns>
        private List<FileInfo> getAllFiles(String folder, SortOrder order)
        {
            var retVal = new List<FileInfo>();

            if (Directory.Exists(folder))
            {
                var fileInfo = new DirectoryInfo(folder).GetFiles();

                switch (order)
                {
                    case SortOrder.DateDescending:
                        retVal = fileInfo.OrderByDescending(f => f.LastWriteTime).ToList();
                        break;

                    case SortOrder.DateAscending:
                        retVal = fileInfo.OrderBy(f => f.LastWriteTime).ToList();
                        break;

                    case SortOrder.AtoZ:
                        retVal = fileInfo.OrderBy(f => f.Name).ToList();
                        break;

                    case SortOrder.ZtoA:
                        retVal = fileInfo.OrderByDescending(f => f.Name).ToList();
                        break;

                    default:
                        retVal = fileInfo.ToList();
                        break;
                }
            }

            return retVal;
        }
开发者ID:glwu,项目名称:acat,代码行数:40,代码来源:FileBrowserScanner.cs


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