/// <summary> /// Gets a list of the contents of a directory at the specified path. /// </summary> /// <param name="path">The path of the directory to get a list of the contents of.</param> /// <param name="getSubDirs">Whether to obtain a list of the contents of all subdirectories as well.</param> /// <returns>An array of strings with the names of directories and files under the supplied path. /// Null if the path is invalid, does not exist, or the current process does not have permission /// to get the directory listing.</returns> static public string[] GetListing(string path, bool getSubDirs) { // Check whether the path supplied is valid. if (!string.IsNullOrEmpty(path)) { // Check whether the path for the directory exits. if (SystemDirectory.Exists(path)) { // The directory exists. // Check if we need to get subdirectory content as well. if (!getSubDirs) { // We don't need to get subdirectory content. try { return(SystemDirectory.GetFileSystemEntries(path)); } catch (UnauthorizedAccessException) { // We don't have the required permission. return(null); } } else { // We need to get subdirectory content as well. return(SystemDirectory.GetFileSystemEntries(path, "*", SearchOption.AllDirectories)); } } } // The path is not valid. return(null); }
public static void IndexDocs(IndexWriter writer, FileInfo file, string target) { if (file.FullName.Contains(target + "\\")) { return; } if (IODir.Exists(file.FullName)) { var files = IODir.GetFileSystemEntries(file.FullName); if (files == null) { return; } for (var i = 0; i < files.Length; i++) { IndexDocs(writer, new FileInfo(files[i]), target); } } else { Console.WriteLine("adding " + file); var doc = IndexDocument(file); writer.AddDocument(doc); } }
/// <summary> /// Lists all the file-system entries contained at a certain directory. /// </summary> /// <param name="path">The path of the directory.</param> /// <returns> /// An array of file-system entry paths. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path" /> is <see langword="null" /> (<see langword="Nothing" /> /// in Visual Basic). /// </exception> public string[] GetFileSystemEntries(string path) { _ = Requires.NotNullOrWhiteSpace( path, nameof(path)); return(FSDir.GetFileSystemEntries(path)); }
/// <summary> /// Lists all the file-system entries contained at a certain directory with a specific search pattern. /// </summary> /// <param name="path">The path of the directory.</param> /// <param name="searchPattern">The search pattern to use.</param> /// <returns> /// An array of file-system entries paths. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path" /> or <paramref name="searchPattern" /> is /// <see langword="null" /> (<see langword="Nothing" /> in Visual Basic). /// </exception> public string[] GetFileSystemEntries( string path, string searchPattern) { _ = Requires.NotNullOrWhiteSpace( path, nameof(path)); _ = Requires.NotNullOrWhiteSpace( searchPattern, nameof(searchPattern)); return(FSDir.GetFileSystemEntries( path, searchPattern)); }
public void Execute() { if ((Directory.Exists(Path.Combine(backupLocation, "Indexes")) == false) || (Directory.Exists(Path.Combine(backupLocation, "IndexDefinitions")) == false)) { throw new InvalidOperationException(backupLocation + " doesn't look like a valid backup"); } if (Directory.Exists(databaseLocation) && Directory.GetFileSystemEntries(databaseLocation).Length > 0) { throw new IOException("Database already exists, cannot restore to an existing database."); } if (Directory.Exists(databaseLocation) == false) { Directory.CreateDirectory(databaseLocation); } Directory.CreateDirectory(Path.Combine(databaseLocation, "logs")); Directory.CreateDirectory(Path.Combine(databaseLocation, "temp")); Directory.CreateDirectory(Path.Combine(databaseLocation, "system")); CopyAll(new DirectoryInfo(Path.Combine(backupLocation, "IndexDefinitions")), new DirectoryInfo(Path.Combine(databaseLocation, "IndexDefinitions"))); CopyAll(new DirectoryInfo(Path.Combine(backupLocation, "Indexes")), new DirectoryInfo(Path.Combine(databaseLocation, "Indexes"))); JET_INSTANCE instance; Api.JetCreateInstance(out instance, "restoring " + Guid.NewGuid()); try { TransactionalStorage.ConfigureInstance(instance, databaseLocation); Api.JetRestoreInstance(instance, backupLocation, databaseLocation, StatusCallback); var fileThatGetsCreatedButDoesntSeemLikeItShould = new FileInfo(Path.Combine(new DirectoryInfo(databaseLocation).Parent.FullName, new DirectoryInfo(databaseLocation).Name + "Data")); if (fileThatGetsCreatedButDoesntSeemLikeItShould.Exists) { fileThatGetsCreatedButDoesntSeemLikeItShould.MoveTo(Path.Combine(databaseLocation, "Data")); } } finally { Api.JetTerm(instance); } }
// This method decides what action to take based on the type of // file we are looking at public static void doFile(FileInfo f) { // If this is a directory, walk each file/dir in that directory if (Directory.Exists(f.FullName)) { string[] files = Directory.GetFileSystemEntries(f.FullName); for (int i = 0; i < files.Length; i++) { doFile(new FileInfo(f.FullName + "\\" + files[i])); } } else if ((f.Name.Length > 5) && f.Name.Substring(f.Name.Length - 5).Equals(".java")) { Console.Error.WriteLine(" " + f.FullName); parseFile(f.Name, new FileStream(f.FullName, FileMode.Open, FileAccess.Read)); } }
public static string[] GetFileSystemEntries(string path, string searchPattern, MSIO.SearchOption searchOption) => MSIOD.GetFileSystemEntries(path, searchPattern, searchOption);
public static string[] GetFileSystemEntries(string path) => MSIOD.GetFileSystemEntries(path);
void DoFiles(DefaultWatcherData data, string directory, bool dispatch) { bool direxists = Directory.Exists(directory); if (direxists && data.IncludeSubdirs) { foreach (string d in Directory.GetDirectories(directory)) { DoFiles(data, d, dispatch); } } string [] files = null; if (!direxists) { files = NoStringsArray; } else if (!data.NoWildcards) { files = Directory.GetFileSystemEntries(directory, data.FileMask); } else { // The pattern does not have wildcards if (File.Exists(data.FileMask) || Directory.Exists(data.FileMask)) { files = new string [] { data.FileMask } } ; else { files = NoStringsArray; } } /* Set all as untested */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData)data.Files [filename]; if (fd.Directory == directory) { fd.NotExists = true; } } /* New files */ foreach (string filename in files) { FileData fd = (FileData)data.Files [filename]; if (fd == null) { try { data.Files.Add(filename, CreateFileData(directory, filename)); } catch { // The file might have been removed in the meanwhile data.Files.Remove(filename); continue; } if (dispatch) { DispatchEvents(data.FSW, FileAction.Added, filename); } } else if (fd.Directory == directory) { fd.NotExists = false; } } if (!dispatch) // We only initialize the file list { return; } /* Removed files */ ArrayList removed = null; foreach (string filename in data.Files.Keys) { FileData fd = (FileData)data.Files [filename]; if (fd.NotExists) { if (removed == null) { removed = new ArrayList(); } removed.Add(filename); DispatchEvents(data.FSW, FileAction.Removed, filename); } } if (removed != null) { foreach (string filename in removed) { data.Files.Remove(filename); } removed = null; } /* Changed files */ foreach (string filename in data.Files.Keys) { FileData fd = (FileData)data.Files [filename]; DateTime creation, write; try { creation = File.GetCreationTime(filename); write = File.GetLastWriteTime(filename); } catch { /* Deleted */ if (removed == null) { removed = new ArrayList(); } removed.Add(filename); DispatchEvents(data.FSW, FileAction.Removed, filename); continue; } if (creation != fd.CreationTime || write != fd.LastWriteTime) { fd.CreationTime = creation; fd.LastWriteTime = write; DispatchEvents(data.FSW, FileAction.Modified, filename); } } if (removed != null) { foreach (string filename in removed) { data.Files.Remove(filename); } } }
/// <summary> /// Gets the file system entries. /// </summary> /// <param name="path">The path.</param> /// <param name="searchPattern">The search pattern.</param> /// <returns></returns> public override string[] GetFileSystemEntries(string path, string searchPattern) { return(Directory.GetFileSystemEntries(path, searchPattern)); }
/// <summary> /// Gets the file system entries. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> public override string[] GetFileSystemEntries(string path) { return(Directory.GetFileSystemEntries(path)); }