/// <summary> /// 子文件夹是否存在 /// </summary> /// <param name="directoryPath">子文件夹的相对路径</param> /// <returns>是否存在</returns> public bool Exists(string directoryPath) { LocalDisk.GuardValidatePath(directoryPath); directoryPath = LocalDisk.NormalizePath(directoryPath); var dir = new DirectoryInfo(path + directoryPath); return(dir.Exists); }
/// <summary> /// 创建子目录文件夹,如果文件夹已经存在那么不会进行任何操作 /// </summary> /// <param name="directoryPath">子目录相对路径</param> /// <returns>子文件夹实例</returns> public IDirectory Create(string directoryPath) { LocalDisk.GuardValidatePath(directoryPath); directoryPath = LocalDisk.NormalizePath(directoryPath); IDirectory directory = null; if (!Exists(path + directoryPath)) { var dir = new DirectoryInfo(path + directoryPath); dir.Create(); } directory = new Directory(path + directoryPath, disk); return(directory); }
/// <summary> /// 返回此目录的子目录(如果存在,反之抛出一个异常) /// </summary> /// <param name="directoryPath">子目录路径</param> /// <returns>子目录文件夹</returns> public IDirectory this[string directoryPath] { get { LocalDisk.GuardValidatePath(directoryPath); directoryPath = LocalDisk.NormalizePath(directoryPath); if (Exists(directoryPath)) { return(new Directory(path + directoryPath, disk)); } else { throw new DirectoryNotFoundException("a directory was not found at " + directoryPath); } } }