/// <summary> /// Jakub's version of how to replace Dictionary(char, int) /// </summary> /// <param name="info"></param> /// <returns></returns> private static List <FileCount> AZThroughStructure(List <FileInfo> info) { List <FileCount> fileCounts = new List <FileCount>(26); FileCount f = new FileCount(); f.Letter = 'A'; f.count = 0; fileCounts.Add(f); for (int i = 0; i < 25; i++) { FileCount ff = new FileCount(); ff.Letter = ++f.Letter; ff.count = 0; fileCounts.Add(ff); } for (int i = 0; i < info.Count; i++) { for (int j = 0; j < fileCounts.Count; j++) { if (info[i].Name.ToUpper().ToCharArray()[0] == fileCounts[j].Letter) { FileCount temp = new FileCount(); temp.Letter = fileCounts[j].Letter; temp.count = fileCounts[j].count + 1; fileCounts[j] = temp; } } } return(fileCounts); }
static FileCount DirParse(string sDir) { FileCount count = new FileCount { filesLessThan10 = 0, filesFrom10to50 = 0, filesOver100 = 0}; try { foreach (string f in Directory.GetFiles(sDir)) { FileInfo fInfo = new FileInfo(f); if (fInfo.Length > 0 && fInfo.Length <= 10 * 1024 * 1024) count.filesLessThan10++; else if (fInfo.Length > 10 * 1024 * 1024 && fInfo.Length <= 50 * 1024 * 1024) count.filesFrom10to50++; else if (fInfo.Length >= 100 * 1024 * 1024) count.filesOver100++; } foreach (string d in Directory.GetDirectories(sDir)) { FileCount res = DirParse(d); count.filesLessThan10 += res.filesLessThan10; count.filesFrom10to50 += res.filesFrom10to50; count.filesOver100 += res.filesOver100; } return count; } catch (System.Exception excpt) { return count; } }
/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns>A hash code for the current <see cref="T:System.Object" />.</returns> public override int GetHashCode() { return(CreatedTime.GetHashCode() ^ DirectoryCount.GetHashCode() ^ FileCount.GetHashCode() ^ ModifiedTime.GetHashCode() ^ Size.GetHashCode()); }
void workerThread_ProgressChanged(object sender, ProgressChangedEventArgs e) { FileInfo fileInfo = e.UserState as FileInfo; TotalFilesLabel.Content = FileCount.ToString(); CurrentFileLabel.Content = fileInfo.Name; CurrentFileSizeLabel.Content = (fileInfo.Length / 1000).ToString() + " KB"; }
public TestInput(DataFolder datafolder, Files files = Files.UnusedParameter, FileCount fileCount = FileCount.UnusedParameter, HeaderCount headerCount = HeaderCount.UnusedParameter, DataRowCount dataRowCount = DataRowCount.UnusedParameter) { this.Timeout = DefaultTimeout; this.DataFolder = datafolder; this.Files = files; this.FileCount = fileCount; this.HeaderCount = headerCount; this.DataRowCount = dataRowCount; }
/// <summary> /// Initialize the formatter to format the file pattern to get a file name. /// </summary> private void InitializeFormatter() { Formatter.SetProperty("Hour", DateTime.Now.Hour.ToString("00")); Formatter.SetProperty("hour", (((DateTime.Now.Hour + 11) % 12) + 1).ToString("00")); Formatter.SetProperty("meridian", (DateTime.Now.Hour >= 12) ? "PM" : "AM"); Formatter.SetProperty("minute", DateTime.Now.Minute.ToString("00")); Formatter.SetProperty("second", DateTime.Now.Second.ToString("00")); Formatter.SetProperty("year", DateTime.Now.Year.ToString("0000")); Formatter.SetProperty("month", DateTime.Now.Month.ToString("00")); Formatter.SetProperty("day", DateTime.Now.Day.ToString("00")); Formatter.SetProperty("dayofweek", DateTime.Now.DayOfWeek.ToString()); Formatter.SetProperty("dayofyear", DateTime.Now.DayOfYear.ToString("000")); Formatter.SetProperty("weekday", DateTime.Now.ToString("dddd")); Formatter.SetProperty("filenumber", FileCount.ToString()); }
public override string ToString() { if (FileCount == -1) { return(""); } else if (FileCount > 0) { return(TopFolderName + " (" + FileCount.ToString() + ")"); } else { return(TopFolderName); } }
void workerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { end = DateTime.Now; TotalFilesLabel.Content = FileCount.ToString(); TotalTimeLabel.Content = (end - start).TotalSeconds.ToString() + " seconds."; DataModel.TimeToScan = (end - start).TotalSeconds.ToString(); // When we stop the scan in between, we don't drop the table or clean it. // We print all the results we have populated so far. DataModel.Clear(); DBQueries.FindDuplicateEntries(this._dbEngine, this.DataModel); _scanInProgress = false; DirScanButton.IsEnabled = true; }
public void Create(FolderPath folderPath, FileCount filesCount) { switch (filesCount) { case FileCount.UnusedParameter: break; case FileCount.Single: new FilesFactory().MakeFolderEmpty(folderPath); new FilesFactory().CreateFile(folderPath, "bar.csv"); break; default: throw new InvalidOperationException(string.Format(@"Error: Unhandled \fileCount parameter value {0}", filesCount)); } }
public static FileCount CountInTextFile(string filePath, bool countLines, bool countWords, bool countChars) { if (!System.IO.File.Exists(filePath)) { throw new FileNotFoundException(); } //whether the file exist int lines = 0, words = 0; long chars = 0; using (StreamReader r = new StreamReader(filePath)) { string sentence; // save each line while ((sentence = r.ReadLine()) != null) { //Console.WriteLine(sentence); lines++; string[] word = sentence.Split(' '); words += word.Length; chars += sentence.Length; } } FileCount result = new FileCount(); result.filePath = filePath; // read one line each iteration so that use less memory. if (countLines) { result.LineCount = lines; Console.WriteLine("The number of lines in this file is " + lines); } if (countWords) { result.WrodCount = words; Console.WriteLine("The number of words in this file is " + words); } if (countChars) { result.CharCount = chars; Console.WriteLine("The number of chars in this file is " + chars); } return(result); }
protected override void Execute(NativeActivityContext context) { try { string folderpath = FolderPath.Get(context); if (Directory.Exists(folderpath)) { var folderInfo = new FileInfo(folderpath); var dirInfo = new DirectoryInfo(folderpath); FolderName.Set(context, folderInfo.Name); // FolderCount.Set(context, folderInfo.Extension); // FileCount.Set(context, folderInfo.Length); FolderCount.Set(context, dirInfo.GetDirectories().Length); FileCount.Set(context, dirInfo.GetFiles().Length); CreationTime.Set(context, folderInfo.CreationTime); LastAccessTime.Set(context, folderInfo.LastAccessTime); LastWriteTime.Set(context, folderInfo.LastWriteTime); } else if (!Directory.Exists(folderpath)) { Log.Logger.LogData("Folder does not exist in path - " + folderpath + " in activity Folder_GetInformation", LogLevel.Error); if (!ContinueOnError) { context.Abort(); } } } catch (Exception ex) { Log.Logger.LogData(ex.Message + " in activity Folder_GetInformation", LogLevel.Error); if (!ContinueOnError) { context.Abort(); } } }
async Task OnExecuteAsync() { OutputPath = Path.GetFullPath(OutputPath); if (File.Exists(OutputPath)) { throw new Exception("O caminho onde os arquivos aleatórios serão gravados precisa ser um diretório"); } if (string.IsNullOrWhiteSpace(FileNameTemplate)) { throw new Exception("Você precisa informar um template válido para nome do arquivo"); } FileNameTemplate = FileNameTemplate.Replace("{n}", "{0}"); if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } if (FileCount < 1) { throw new Exception("Você precisa informar pelo menos 1 arquivo para gerar"); } if (string.IsNullOrWhiteSpace(MinFileSize)) { throw new Exception("Você precisa informar o parâmetro --min-file-size"); } if (string.IsNullOrWhiteSpace(MaxFileSize)) { throw new Exception("Você precisa informar o parâmetro --max-file-size"); } var minFileSize = ParseHumanSize(MinFileSize); var maxFileSize = ParseHumanSize(MaxFileSize); if (minFileSize < 1) { throw new Exception("O tamanho mínimo do arquivo aleatório precisa ser de pelo menos 1 byte"); } if (maxFileSize < minFileSize) { throw new Exception("O tamanho máximo do arquivo aleatório precisa ser pelo menos o mesmo tamanho mínimo"); } var currentFile = 1; var fileCountCharactersSize = FileCount.ToString().Length; var rnd = new Random(); while (currentFile <= FileCount) { var fileNumber = (currentFile++).ToString().PadLeft(fileCountCharactersSize, '0'); var fileName = string.Format(FileNameTemplate, fileNumber); var filePath = Path.Combine(OutputPath, fileName); var fileSize = rnd.Next(minFileSize, maxFileSize); Console.WriteLine("Gerando arquivo {0} com {1}...", fileName, FormatHumanSize(fileSize)); var fileBytes = new Byte[fileSize]; rnd.NextBytes(fileBytes); using (var stream = new FileStream(filePath, FileMode.Create)) await stream.WriteAsync(fileBytes, 0, fileSize); } }