Exemplo n.º 1
0
        /// <summary>
        /// 复制文件夹
        /// </summary>
        /// <param name="targetDirectroy">目标文件夹</param>
        public IDirectory CopyTo(string targetDirectroy)
        {
            LocalDisk.GuardValidatePath(targetDirectroy);
            IDirectory dir = new Directory(targetDirectroy, disk);

            dir.Create();

            var files = System.IO.Directory.GetFiles(Path);

            string fileName;
            string destFile;

            foreach (var s in files)
            {
                fileName = System.IO.Path.GetFileName(s);
                destFile = targetDirectroy + System.IO.Path.AltDirectorySeparatorChar + fileName;
                System.IO.File.Copy(s, destFile, true);
            }

            IDirectory drinfo;

            foreach (var info in System.IO.Directory.GetDirectories(Path))
            {
                drinfo = new Directory(info, disk);
                drinfo.CopyTo(targetDirectroy + System.IO.Path.AltDirectorySeparatorChar + drinfo.Name);
            }

            return(((Directory)dir).Refresh());
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 移动到指定文件
 /// </summary>
 /// <param name="targetDirectory">目标文件夹</param>
 public void MoveTo(string targetDirectory)
 {
     LocalDisk.GuardValidatePath(targetDirectory);
     (new Directory(targetDirectory, disk)).Create();
     FileInfo.MoveTo(targetDirectory + Path.AltDirectorySeparatorChar + fileName + extension);
     directory = targetDirectory;
     Refresh();
 }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 /// <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);
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 构建一个文件夹
 /// </summary>
 /// <param name="directoryPath">默认根路径</param>
 /// <param name="disk">本地磁盘</param>
 public Directory(string directoryPath, LocalDisk disk)
 {
     LocalDisk.GuardValidatePath(directoryPath);
     this.disk = disk;
     path      = directoryPath;
 }