// Returns an array of Directories in the current DirectoryInfo matching the // given search criteria (ie, "*.txt"). /// <include file='doc\Directory.uex' path='docs/doc[@for="Directory.GetDirectories1"]/*' /> public static String[] GetDirectories(String path, String searchPattern) { if (path == null) { throw new ArgumentNullException("path"); } if (searchPattern == null) { throw new ArgumentNullException("searchPattern"); } searchPattern = searchPattern.TrimEnd(); if (searchPattern.Length == 0) { return(new String[0]); } Path.CheckSearchPattern(searchPattern); // Must fully qualify the path for the security check String fullPath = Path.GetFullPathInternal(path); String demandPath; if (fullPath.EndsWith(Path.DirectorySeparatorChar)) { demandPath = fullPath + "."; } else { demandPath = fullPath + Path.DirectorySeparatorChar + "."; } new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new String[] { demandPath }, false, false).Demand(); String searchPath = Path.GetDirectoryName(searchPattern); if (searchPath != null && searchPath != String.Empty) // For filters like foo\*.cs we need to verify if the directory foo is not denied access. { demandPath = Path.InternalCombine(fullPath, searchPath); if (demandPath.EndsWith(Path.DirectorySeparatorChar)) { demandPath = demandPath + "."; } else { demandPath = demandPath + Path.DirectorySeparatorChar + "."; } new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new String[] { demandPath }, false, false).Demand(); path = Path.Combine(path, searchPath); // Need to add the searchPath to return correct path and for right security checks } String [] dirNames = InternalGetDirectories(fullPath, searchPattern); for (int i = 0; i < dirNames.Length; i++) { dirNames[i] = Path.InternalCombine(path, dirNames[i]); } return(dirNames); }
// Returns an array of Directories in the current DirectoryInfo matching the // given search criteria (ie, "System*" could match the System & System32 // directories). /// <include file='doc\DirectoryInfo.uex' path='docs/doc[@for="DirectoryInfo.GetDirectories1"]/*' /> public DirectoryInfo[] GetDirectories(String searchPattern) { new FileIOPermission(FileIOPermissionAccess.PathDiscovery, demandDir, false, false).Demand(); if (searchPattern == null) { throw new ArgumentNullException("searchPattern"); } searchPattern = searchPattern.TrimEnd(); if (searchPattern.Length == 0) { return(new DirectoryInfo[0]); } Path.CheckSearchPattern(searchPattern); String path = FullPath; String searchPath = Path.GetDirectoryName(searchPattern); if (searchPath != null && searchPath != String.Empty) // For filters like foo\*.cs we need to verify if the directory foo is not denied access. { String demandPath = Path.InternalCombine(FullPath, searchPath); if (demandPath.EndsWith(Path.DirectorySeparatorChar)) { demandPath = demandPath + "."; } else { demandPath = demandPath + Path.DirectorySeparatorChar + "."; } new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new String[] { demandPath }, false, false).Demand(); path = Path.Combine(path, searchPath); } String fullPath = Path.InternalCombine(FullPath, searchPattern); String[] dirNames = Directory.InternalGetFileDirectoryNames(fullPath, false); String[] permissionNames = new String[dirNames.Length]; for (int i = 0; i < dirNames.Length; i++) { dirNames[i] = Path.InternalCombine(path, dirNames[i]); permissionNames[i] = dirNames[i] + "\\."; // these will never have a slash at end } if (dirNames.Length != 0) { new FileIOPermission(FileIOPermissionAccess.Read, permissionNames, false, false).Demand(); } DirectoryInfo[] dirs = new DirectoryInfo[dirNames.Length]; for (int i = 0; i < dirNames.Length; i++) { dirs[i] = new DirectoryInfo(dirNames[i], false); } return(dirs); }
// Token: 0x060018A2 RID: 6306 RVA: 0x00050A18 File Offset: 0x0004EC18 private static string NormalizeSearchPattern(string searchPattern) { string text = searchPattern.TrimEnd(Path.TrimEndChars); if (text.Equals(".")) { text = "*"; } Path.CheckSearchPattern(text); return(text); }
private static string NormalizeSearchPattern(string searchPattern) { string searchPattern1 = searchPattern.TrimEnd(Path.TrimEndChars); if (searchPattern1.Equals(".")) { searchPattern1 = "*"; } Path.CheckSearchPattern(searchPattern1); return(searchPattern1); }
// Returns an array of strongly typed FileSystemInfo entries in the path with the // given search criteria (ie, "*.txt"). /// <include file='doc\DirectoryInfo.uex' path='docs/doc[@for="DirectoryInfo.GetFileSystemInfos"]/*' /> public FileSystemInfo[] GetFileSystemInfos(String searchPattern) { new FileIOPermission(FileIOPermissionAccess.PathDiscovery, demandDir, false, false).Demand(); if (searchPattern==null) throw new ArgumentNullException("searchPattern"); searchPattern = searchPattern.TrimEnd(); if (searchPattern.Length == 0) return new FileSystemInfo[0]; Path.CheckSearchPattern(searchPattern); String path = FullPath; String searchPath = Path.GetDirectoryName(searchPattern); if (searchPath != null && searchPath != String.Empty) // For filters like foo\*.cs we need to verify if the directory foo is not denied access. { String demandPath = Path.InternalCombine(FullPath,searchPath); if (demandPath.EndsWith( '\\' )) demandPath = demandPath + "."; else demandPath = demandPath + "\\."; new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new String[] { demandPath }, false, false).Demand(); path = Path.Combine(path,searchPath); } String [] dirNames = Directory.InternalGetDirectories(FullPath, OriginalPath, searchPattern); String [] fileNames = Directory.InternalGetFiles(FullPath, OriginalPath, searchPattern); FileSystemInfo [] fileSystemEntries = new FileSystemInfo[dirNames.Length + fileNames.Length]; String[] permissionNames = new String[dirNames.Length]; for (int i = 0;i<dirNames.Length;i++) { dirNames[i] = Path.InternalCombine(path, dirNames[i]); permissionNames[i] = dirNames[i] + "\\."; } if (dirNames.Length != 0) new FileIOPermission(FileIOPermissionAccess.Read,permissionNames,false,false).Demand(); for (int i = 0;i<fileNames.Length;i++) fileNames[i] = Path.InternalCombine(path, fileNames[i]); if (fileNames.Length != 0) new FileIOPermission(FileIOPermissionAccess.Read,fileNames,false,false).Demand(); int count = 0; for (int i = 0;i<dirNames.Length;i++) fileSystemEntries[count++] = new DirectoryInfo(dirNames[i], false); for (int i = 0;i<fileNames.Length;i++) fileSystemEntries[count++] = new FileInfo(fileNames[i], false); return fileSystemEntries; }
private static String NormalizeSearchPattern(String searchPattern) { Contract.Requires(searchPattern != null); // Win32 normalization trims only U+0020. String tempSearchPattern = searchPattern.TrimEnd(Path.TrimEndChars); // Make this corner case more useful, like dir if (tempSearchPattern.Equals(".")) { tempSearchPattern = "*"; } Path.CheckSearchPattern(tempSearchPattern); return(tempSearchPattern); }