Esempio n. 1
0
        /// <summary>
        /// 迭代的复制指定属性的文件
        /// </summary>
        /// <param name="newFolder"></param>
        /// <param name="type"></param>
        /// <param name="fileAttr"></param>
        /// <param name="dirAttr"></param>
        public void batchTreeCopyFromByAttribute(String newFolder, FileAttributes fileAttr, FileAttributes dirAttr)
        {
            DirectoryInfo newDir = new DirectoryInfo(newFolder);

            if (newDir.Exists && !newDir.FullName.ToLower().Equals(dir.FullName.ToLower()))
            {
                FileInfo[] files = newDir.GetFiles();
                for (int i = 0; i < files.Length; i++)
                {
                    if ((files[i].Attributes & fileAttr) != 0)
                    {
                        FileFunction fileFunc = new FileFunction(files[i]);
                        fileFunc.CopyTo(dir.FullName);
                    }
                }
                DirectoryInfo[] dirs = newDir.GetDirectories();
                for (int i = 0; i < dirs.Length; i++)
                {
                    if ((dirs[i].Attributes & dirAttr) == 0)
                    {
                        DirectoryFunction dirFunc = new DirectoryFunction(dir);
                        dirFunc.batchTreeCopyFromByAttribute(dirs[i].FullName, fileAttr, dirAttr);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 将当前目录下的文件复制到指定目录中
        /// </summary>
        /// <param name="newFolder"></param>
        /// <param name="attr"></param>
        public void batchCopyTo(String newFolder, FileAttributes attr)
        {
            DirectoryInfo newDir = new DirectoryInfo(newFolder);

            if (newDir.Exists)
            {
                if (!newDir.FullName.ToLower().Equals(dir.FullName.ToLower()))
                {
                    for (int i = 0; i < childFiles.Length; i++)
                    {
                        if ((childFiles[i].Attributes & attr) == 0)
                        {
                            FileFunction file = new FileFunction(childFiles[i]);
                            file.CopyTo(newDir.FullName);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 迭代得把源目录下的文件复制到每一个子目录中,排除文件,目录属性
        /// </summary>
        /// <param name="sourceDir"></param>
        /// <param name="fileAttr"></param>
        /// <param name="dirAttr"></param>
        private void batchTreeAddFileForDirectory(DirectoryInfo sourceDir, FileAttributes fileAttr, FileAttributes dirAttr)
        {
            for (int i = 0; i < childDirs.Length; i++)
            {
                if ((childDirs[i].Attributes & dirAttr) == 0)
                {
                    FileInfo[] subFiles = sourceDir.GetFiles();
                    for (int j = 0; j < subFiles.Length; j++)
                    {
                        if ((subFiles[j].Attributes & fileAttr) == 0)
                        {
                            FileFunction subFile = new FileFunction(subFiles[j]);
                            subFile.CopyTo(childDirs[i].FullName);
                        }
                    }

                    DirectoryFunction dirFunc = new DirectoryFunction(childDirs[i]);
                    dirFunc.batchTreeAddFileForDirectory(sourceDir, fileAttr, dirAttr);
                }
            }
        }