⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directory.cs

📁 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的
💻 CS
📖 第 1 页 / 共 2 页
字号:
	// the specified search criteria, returning FileSystemInfo's.	internal static Object ScanDirectoryForInfos				(String path, String searchPattern,				 ScanType scanType, Type arrayType)			{				Regex regex;				ArrayList list;				InternalFileInfo[] entries;				Errno error;				int posn;				String filename;				FileType type;				// Get all files in the directory.				error = DirMethods.GetFilesInDirectory(path, out entries);				if(error != Errno.Success)				{					HandleErrorsDir(error);				}				if(entries == null)				{					return new String [0];				}				// Convert the search pattern into a regular expression.				if(searchPattern == null)				{					regex = null;				}				else				{					regex = new Regex(searchPattern, RegexSyntax.Wildcard);				}				// Scan the file list and collect up matching entries.				list = new ArrayList (entries.Length);				for(posn = 0; posn < entries.Length; ++posn)				{					filename = entries[posn].fileName;					if(filename == "." || filename == "..")					{						continue;					}					type = entries[posn].fileType;					switch(scanType)					{						case ScanType.Directories:						{							if(type != FileType.directory)							{								continue;							}						}						break;						case ScanType.Files:						{							if(type == FileType.directory)							{								continue;							}						}						break;						default: break;					}					if(regex != null && !regex.Match(filename))					{						continue;					}					if(type == FileType.directory)					{						list.Add(new DirectoryInfo									(Path.Combine(path, filename)));					}					else					{						list.Add(new FileInfo(Path.Combine(path, filename)));					}				}				// Dispose of the regular expression.				if(regex != null)				{					regex.Dispose();				}				// Return the list of strings to the caller.				return list.ToArray(arrayType);			}#endif // !ECMA_COMPAT	// Get the sub-directories under a specific directory.	public static String[] GetDirectories(String path)			{				ValidatePath(path);				return ScanDirectory(path, null, ScanType.Directories);			}	public static String[] GetDirectories(String path, String searchPattern)			{				ValidatePath(path);				if(searchPattern == null)				{					throw new ArgumentNullException("searchPattern");				}				return ScanDirectory(path, searchPattern,									 ScanType.Directories);			}	// Get the root directory for a specific path.	public static String GetDirectoryRoot(String path)			{				return Path.GetPathRoot(path);			}	// Get the files under a specific directory.	public static String[] GetFiles(String path)			{				ValidatePath(path);				return ScanDirectory(path, null, ScanType.Files);			}	public static String[] GetFiles(String path, String searchPattern)			{				ValidatePath(path);				if(searchPattern == null)				{					throw new ArgumentNullException("searchPattern");				}				return ScanDirectory(path, searchPattern,									 ScanType.Files);			}	// Get all filesystem entries under a specific directory.	public static String[] GetFileSystemEntries(String path)			{				ValidatePath(path);				return ScanDirectory(path, null, ScanType.DirectoriesAndFiles);			}	public static String[] GetFileSystemEntries					(String path, String searchPattern)			{				ValidatePath(path);				if(searchPattern == null)				{					throw new ArgumentNullException("searchPattern");				}				return ScanDirectory(path, searchPattern,									 ScanType.DirectoriesAndFiles);			}	// Get the last access time of a directory.	public static DateTime GetLastAccessTime(String path)			{				long time;				ValidatePath(path);				HandleErrorsDir(DirMethods.GetLastAccess(path, out time));				return (new DateTime(time)).ToLocalTime();			}	// Get the last modification time of a directory.	public static DateTime GetLastWriteTime(String path)			{				long time;				ValidatePath(path);				HandleErrorsDir(DirMethods.GetLastModification(path, out time));				return (new DateTime(time)).ToLocalTime();			}	// Move a file or directory to a new location.	public static void Move(String sourceDirName, String destDirName)			{				ValidatePath(sourceDirName);				ValidatePath(destDirName);				HandleErrorsFile(DirMethods.Rename(sourceDirName, destDirName));			}	// Set a directory's creation time.	public static void SetCreationTime(String path, DateTime creationTime)			{				ValidatePath(path);				long ticks = creationTime.ToUniversalTime().Ticks;				HandleErrorsDir(FileMethods.SetCreationTime(path, ticks));			}	// Set the current directory.	public static void SetCurrentDirectory(String path)			{				ValidatePath(path);				HandleErrorsDir(DirMethods.ChangeDirectory(path));			}	// Set a directory's last access time.	public static void SetLastAccessTime(String path, DateTime lastAccessTime)			{				ValidatePath(path);				long ticks = lastAccessTime.ToUniversalTime().Ticks;				HandleErrorsDir(FileMethods.SetLastAccessTime(path, ticks));			}	// Set a directory's last write time.	public static void SetLastWriteTime(String path, DateTime lastWriteTime)			{				ValidatePath(path);				long ticks = lastWriteTime.ToUniversalTime().Ticks;				HandleErrorsDir(FileMethods.SetLastWriteTime(path, ticks));			}#if !ECMA_COMPAT	// Create a directory, including parent directories.	public static DirectoryInfo CreateDirectory(String path)			{				ValidatePath(path);				Errno error = DirMethods.CreateDirectory(path);				if(error != Errno.Success)				{					// The path may already exist.					if(Exists(path))					{						return new DirectoryInfo(path);					}					// Attempt to create the parent directory.					String parent = Path.GetDirectoryName(path);					if(parent == null)					{						HandleErrorsDir(error);					}					CreateDirectory(parent);					// Now try creating the child directory again.					error = DirMethods.CreateDirectory(path);					if(error != Errno.Success)					{						HandleErrorsDir(error);					}				}				return new DirectoryInfo(path);			}	// Get the UTC creation time of a directory.	public static DateTime GetCreationTimeUtc(String path)			{				long time;				ValidatePath(path);				HandleErrorsDir(DirMethods.GetCreationTime(path, out time));				return new DateTime(time);			}	// Get the UTC last access time of a directory.	public static DateTime GetLastAccessTimeUtc(String path)			{				long time;				ValidatePath(path);				HandleErrorsDir(DirMethods.GetLastAccess(path, out time));				return new DateTime(time);			}	// Get the UTC last modification time of a directory.	public static DateTime GetLastWriteTimeUtc(String path)			{				long time;				ValidatePath(path);				HandleErrorsDir(DirMethods.GetLastModification(path, out time));				return new DateTime(time);			}	// Get the logical drive letters.	public static String[] GetLogicalDrives()			{				return DirMethods.GetLogicalDrives();			}	// Get the parent of a specific directory.	public static DirectoryInfo GetParent(String path)			{				int index, index2;				if(path == null)				{					throw new ArgumentNullException("path");				}				path = Path.GetFullPath(path);				index = path.LastIndexOf(Path.DirectorySeparatorChar);				index2 = path.LastIndexOf(Path.AltDirectorySeparatorChar);				if(index2 > index)				{					index = index2;				}				if(index <= 0)				{					return null;				}				return new DirectoryInfo(path.Substring(0, index));			}	// Set a directory's UTC creation time.	public static void SetCreationTimeUtc(String path, DateTime creationTime)			{				ValidatePath(path);				long ticks = creationTime.Ticks;				HandleErrorsDir(FileMethods.SetCreationTime(path, ticks));			}	// Set a directory's UTC last access time.	public static void SetLastAccessTimeUtc				(String path, DateTime lastAccessTime)			{				ValidatePath(path);				long ticks = lastAccessTime.Ticks;				HandleErrorsDir(FileMethods.SetLastAccessTime(path, ticks));			}	// Set a directory's UTC last write time.	public static void SetLastWriteTimeUtc(String path, DateTime lastWriteTime)			{				ValidatePath(path);				long ticks = lastWriteTime.Ticks;				HandleErrorsDir(FileMethods.SetLastWriteTime(path, ticks));			}#endif // !ECMA_COMPAT}; // class Directory}; // namespace System.IO

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -