Exemple #1
0
        public directoy(path path, DirectoryInfo dx, bool allowCleanFolders)
        {
            Info        = dx;
            Name        = dx.Name;
            FullName    = dx.FullName;
            PartialPath = FullName.Remove(0, path.InitialDir.Length);

            Dirs = new Dictionary <string, directoy>();
            foreach (DirectoryInfo d1 in dx.GetDirectories())
            {
                directoy d = new directoy(path, d1, allowCleanFolders);

                Dirs.Add(d.Name, d);
            }

            Files = new Dictionary <string, file>();
            foreach (FileInfo d1 in dx.GetFiles())
            {
                file f = new file(path.InitialDir, d1);
                if (!f.CheckLike(path.LikeString))
                {
                    continue;
                }

                path.NumFiles++;
                path.TotalBytes += d1.Length;
                Files.Add(f.Name, f);
            }

            if (!allowCleanFolders && Files.Count <= 0)
            {
                return;
            }
            path.NumDirectories++;
        }
Exemple #2
0
        /// <summary>
        /// Obtiene la ruta a extraer
        /// </summary>
        /// <param name="dir">Directorio</param>
        /// <param name="likeString">Condición</param>
        /// <param name="allowCleanFolders">Permite o no las carpetas vacias</param>
        /// <returns>Devuelve la ruta</returns>
        public static path GetDirFromPath(string dir, string[] likeString, bool allowCleanFolders)
        {
            path p = new path();

            p.InitialDir = dir;
            p.LikeString = likeString;

            foreach (DirectoryInfo di in new DirectoryInfo(dir).GetDirectories())
            {
                directoy dx = new directoy(p, di, allowCleanFolders);
                if (!allowCleanFolders && dx.Files.Count <= 0)
                {
                    continue;
                }

                p.Dirs.Add(dx.Name, dx);
            }
            foreach (FileInfo di in new DirectoryInfo(dir).GetFiles("*", SearchOption.TopDirectoryOnly))
            {
                file dx = new file(dir, di);
                if (!dx.CheckLike(likeString))
                {
                    continue;
                }

                p.NumFiles++;
                p.TotalBytes += dx.Info.Length;
                p.Files.Add(dx.Name, dx);
            }
            return(p);
        }
Exemple #3
0
        /// <summary>
        /// Copia el directorio completo
        /// </summary>
        /// <param name="dir">Directorio</param>
        /// <param name="dirDest">Destino</param>
        public static void CopyTo(directoy dir, string dirDest)
        {
            try
            {
                DirectoryInfo dest = new DirectoryInfo(dirDest + dir.PartialPath);
                if (!dest.Exists)
                {
                    Directory.CreateDirectory(dest.FullName);
                }
                // Crea el directorio, copiar privilegios
                dir.CopyAttributes(dest);
            }
            catch { }

            foreach (directoy d in dir.Dirs.Values)
            {
                CopyTo(d, dirDest);
            }
            foreach (file d in dir.Files.Values)
            {
                file.CopyTo(d, dirDest, 0);
            }
        }