Beispiel #1
0
        /// <summary>
        /// 获取指定路径下一层的除指定格式以外的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        public List <string> GetSubFilesExcept(string path, string exName)
        {
            List <string> names = new List <string>();

            if (IsDirectoryExists(path) == false)
            {
                return(names);
            }

            DirectoryInfo root = new DirectoryInfo(path);

            FileInfo[] files = root.GetFiles();
            string     ex;

            for (int i = 0; i < files.Length; i++)
            {
                ex = FilePathHelper.GetExName(files[i].FullName);
                if (ex == exName)
                {
                    continue;
                }
                names.Add(StringTools.ChangePathFormat(files[i].FullName));
            }

            return(names);
        }
Beispiel #2
0
        /// <summary>
        /// 获取某目录下所有指定类型的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        public List <string> GetAllFiles(string path, string exName)
        {
            if (!IsDirectoryExists(path))
            {
                return(null);
            }
            bool needCheckExName = true;

            exName = exName.ToLower();
            if (string.IsNullOrEmpty(exName))
            {
                needCheckExName = false;
            }
            List <string> names = new List <string>();
            DirectoryInfo root  = new DirectoryInfo(path);

            FileInfo[] files = root.GetFiles();
            string     ex;

            for (int i = 0; i < files.Length; i++)
            {
                if (needCheckExName == true)
                {
                    ex = FilePathHelper.GetExName(files[i].FullName);
                    ex = ex.ToLower();
                    if (ex != exName)
                    {
                        continue;
                    }
                }
                names.Add(StringTools.ChangePathFormat(files[i].FullName));
            }
            DirectoryInfo[] dirs = root.GetDirectories();
            if (dirs.Length > 0)
            {
                for (int i = 0; i < dirs.Length; i++)
                {
                    List <string> subNames = GetAllFiles(dirs[i].FullName, exName);
                    if (subNames.Count > 0)
                    {
                        for (int j = 0; j < subNames.Count; j++)
                        {
                            names.Add(StringTools.ChangePathFormat(subNames[j]));
                        }
                    }
                }
            }

            return(names);
        }
Beispiel #3
0
        /// <summary>
        /// 获取指定路径下第一层的子文件夹路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public List <string> GetSubFolders(string path)
        {
            if (!IsDirectoryExists(path))
            {
                return(null);
            }
            DirectoryInfo root = new DirectoryInfo(path);

            DirectoryInfo[] dirs    = root.GetDirectories();
            List <string>   folders = new List <string>();

            if (dirs.Length > 0)
            {
                for (int i = 0; i < dirs.Length; i++)
                {
                    folders.Add(StringTools.ChangePathFormat(dirs[i].FullName));
                }
            }

            return(folders);
        }
Beispiel #4
0
        /// <summary>
        /// 获取某目录下所有除了指定类型外的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        public List <string> GetAllFilesExceptList(string path, List <string> exName)
        {
            List <string> names = new List <string>();
            DirectoryInfo root  = new DirectoryInfo(path);

            FileInfo[] files = root.GetFiles();
            for (int i = 0; i < exName.Count; i++)
            {
                exName[i] = exName[i].ToLower();
            }
            string ex;

            for (int i = 0; i < files.Length; i++)
            {
                ex = FilePathHelper.GetExName(files[i].FullName);
                ex = ex.ToLower();
                if (exName.IndexOf(ex) >= 0)
                {
                    continue;
                }
                names.Add(StringTools.ChangePathFormat(files[i].FullName));
            }
            DirectoryInfo[] dirs = root.GetDirectories();
            if (dirs.Length > 0)
            {
                for (int i = 0; i < dirs.Length; i++)
                {
                    List <string> subNames = GetAllFilesExceptList(dirs[i].FullName, exName);
                    if (subNames.Count > 0)
                    {
                        for (int j = 0; j < subNames.Count; j++)
                        {
                            names.Add(StringTools.ChangePathFormat(subNames[j]));
                        }
                    }
                }
            }

            return(names);
        }
Beispiel #5
0
        /// <summary>
        /// 获取某目录下所有除了指定类型外的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        public List <string> GetAllFilesExcept(string path, string exName)
        {
            if (!Directory.Exists(path))
            {
                return(null);
            }
            List <string> names = new List <string>();
            DirectoryInfo root  = new DirectoryInfo(path);

            FileInfo[] files = root.GetFiles();
            string     ex;

            for (int i = 0; i < files.Length; i++)
            {
                ex = FilePathHelper.GetExName(files[i].FullName);
                if (ex == exName)
                {
                    continue;
                }
                names.Add(StringTools.ChangePathFormat(files[i].FullName));
            }
            DirectoryInfo[] dirs = root.GetDirectories();
            if (dirs.Length > 0)
            {
                for (int i = 0; i < dirs.Length; i++)
                {
                    List <string> subNames = GetAllFilesExcept(dirs[i].FullName, exName);
                    if (subNames.Count > 0)
                    {
                        for (int j = 0; j < subNames.Count; j++)
                        {
                            names.Add(StringTools.ChangePathFormat(subNames[j]));
                        }
                    }
                }
            }

            return(names);
        }