// private // Does the common validation, searchPattern has already been checked for not-null static string ValidateDirectoryListing(string path, string searchPattern, out bool stop) { Path.Validate(path); string wild = Path.Combine(path, searchPattern); string wildpath = Path.GetDirectoryName(wild); if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Pattern contains invalid characters", "pattern"); } MonoIOError error; if (!MonoIO.ExistsDirectory(wildpath, out error)) { if (error == MonoIOError.ERROR_SUCCESS) { MonoIOError file_error; if (MonoIO.ExistsFile(wildpath, out file_error)) { stop = true; return(wildpath); } } if (error != MonoIOError.ERROR_PATH_NOT_FOUND) { throw MonoIO.GetException(wildpath, error); } if (wildpath.IndexOfAny(SearchPattern.WildcardChars) == -1) { throw new DirectoryNotFoundException("Directory '" + wildpath + "' not found."); } if (path.IndexOfAny(SearchPattern.WildcardChars) == -1) { throw new ArgumentException("Pattern is invalid", "searchPattern"); } throw new ArgumentException("Path is invalid", "path"); } stop = false; return(wild); }
public static bool Exists(string path) { // For security reasons no exceptions are // thrown, only false is returned if there is // any problem with the path or permissions. // Minimizes what information can be // discovered by using this method. if (path == null || path.Trim().Length == 0 || path.IndexOfAny(Path.InvalidPathChars) >= 0) { return(false); } MonoIOError error; return(MonoIO.ExistsFile(path, out error)); }
public static bool Exists(string path) { // For security reasons no exceptions are // thrown, only false is returned if there is // any problem with the path or permissions. // Minimizes what information can be // discovered by using this method. if (String.IsNullOrWhiteSpace(path) || path.IndexOfAny(Path.InvalidPathChars) >= 0) { return(false); } // on Moonlight this does not throw but returns false if (!SecurityManager.CheckElevatedPermissions()) { return(false); } MonoIOError error; return(MonoIO.ExistsFile(path, out error)); }
private static string [] GetFileSystemEntries(string path, string searchPattern, FileAttributes mask, FileAttributes attrs) { if (path == null || searchPattern == null) { throw new ArgumentNullException(); } if (searchPattern.Length == 0) { return new string [] {} } ; if (path.Trim().Length == 0) { throw new ArgumentException("The Path does not have a valid format"); } string wild = Path.Combine(path, searchPattern); string wildpath = Path.GetDirectoryName(wild); if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("Path contains invalid characters"); } if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1) { if (path.IndexOfAny(SearchPattern.InvalidChars) == -1) { throw new ArgumentException("Path contains invalid characters", "path"); } throw new ArgumentException("Pattern contains invalid characters", "pattern"); } MonoIOError error; if (!MonoIO.ExistsDirectory(wildpath, out error)) { if (error == MonoIOError.ERROR_SUCCESS) { MonoIOError file_error; if (MonoIO.ExistsFile(wildpath, out file_error)) { return(new string [] { wildpath }); } } if (error != MonoIOError.ERROR_PATH_NOT_FOUND) { throw MonoIO.GetException(wildpath, error); } if (wildpath.IndexOfAny(SearchPattern.WildcardChars) == -1) { throw new DirectoryNotFoundException("Directory '" + wildpath + "' not found."); } if (path.IndexOfAny(SearchPattern.WildcardChars) == -1) { throw new ArgumentException("Pattern is invalid", "searchPattern"); } throw new ArgumentException("Path is invalid", "path"); } string path_with_pattern = Path.Combine(wildpath, searchPattern); string [] result = MonoIO.GetFileSystemEntries(path, path_with_pattern, (int)attrs, (int)mask, out error); if (error != 0) { throw MonoIO.GetException(wildpath, error); } return(result); }