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()); }
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); }); }
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); } }
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); } }
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); }
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."); }
/*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) { } } }
/// <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; }
/// <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; }