long[] GetLastFileModifiedFast(string dir, string searchPattern, SearchOption searchOption) { //DateTime retval = DateTime.MinValue; //List<string> results = new List<string>(); long[] ret = new long[2]; System.Collections.Generic.IEnumerable <FileData> xxx = FastDirectoryEnumerator.EnumerateFiles(dir, searchPattern, searchOption).ToList(); // yoji. Need "using System.Linq" long numberOfDirectory = 0; long numberOfFiles = 0; foreach (FileData f in xxx) { //if (f.LastWriteTimeUtc > retval) //{ // retval = f.LastWriteTimeUtc; //} /* yoji */ //results.Add(f.depth + ":" + f.Path); string parentFolderAndSubFolder = ""; string strAttributes = ""; //f.Attributes.ToString(); if (((FileAttributes)f.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { strAttributes = "Directory";// Attribute can be "Hidden | Directory" numberOfDirectory++; string[] str = (f.Path).Split(Path.DirectorySeparatorChar); parentFolderAndSubFolder = str[str.Length - 2] + "\\" + f.Name; } else { strAttributes = "File"; numberOfFiles++; } long lenFullPath = f.Path.Length; long lenName = f.Name.Length; ListViewItem lvi; lvi = listView1.Items.Add(f.Path); // full path lvi.SubItems.Add((f.Size).ToString()); lvi.SubItems.Add(strAttributes); lvi.SubItems.Add((f.Path.Length).ToString()); lvi.SubItems.Add(f.Path.Substring(0, (int)(lenFullPath - lenName))); lvi.SubItems.Add(f.Name); lvi.SubItems.Add(f.LastWriteTimeUtc.ToString()); lvi.SubItems.Add(f.CreationTimeUtc.ToString()); lvi.SubItems.Add(f.LastAccessTimeUtc.ToString()); lvi.SubItems.Add(f.depth.ToString()); lvi.SubItems.Add(parentFolderAndSubFolder); //listView1.SelectedItems[0].SubItems[0].Text; } ret[0] = numberOfDirectory; ret[1] = numberOfFiles; return(ret); }
/// <summary> /// Gets <see cref="FileData"/> for all the files in a directory that match a /// specific filter. /// </summary> /// <param name="path">The path to search.</param> /// <param name="searchPattern">The search string to match against files in the path.</param> /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and /// allows you to enumerate the files in the given directory.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is a null reference (Nothing in VB) /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="filter"/> is a null reference (Nothing in VB) /// </exception> public static FileData[] GetFiles(string path, string searchPattern, SearchOption searchOption) { IEnumerable <FileData> e = FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, searchOption); List <FileData> list = new List <FileData>(e); FileData[] retval = new FileData[list.Count]; list.CopyTo(retval); return(retval); }
DateTime GetLastFileModifiedFast(string dir, string searchPattern, SearchOption searchOption) { DateTime retval = DateTime.MinValue; foreach (FileData f in FastDirectoryEnumerator.EnumerateFiles(dir, searchPattern, searchOption)) { if (f.LastWriteTimeUtc > retval) { retval = f.LastWriteTimeUtc; } } return(retval); }
/// <summary> /// Gets <see cref="FileData"/> for all the files in a directory that match a /// specific filter. /// </summary> /// <param name="path">The path to search.</param> /// <param name="searchPattern">The search string to match against files in the path.</param> /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and /// allows you to enumerate the files in the given directory.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is a null reference (Nothing in VB) /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="filter"/> is a null reference (Nothing in VB) /// </exception> public static IEnumerable <FileData> EnumerateFiles(string path, string searchPattern) { return(FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, SearchOption.TopDirectoryOnly)); }
/// <summary> /// Gets <see cref="FileData"/> for all the files in a directory. /// </summary> /// <param name="path">The path to search.</param> /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and /// allows you to enumerate the files in the given directory.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is a null reference (Nothing in VB) /// </exception> public static IEnumerable <FileData> EnumerateFiles(string path) { return(FastDirectoryEnumerator.EnumerateFiles(path, "*")); }