Esempio n. 1
0
        /// <summary>
        /// 获取指定路径下一层的除指定格式以外的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        static 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);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取某目录下所有除了指定类型外的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        static public List <string> GetAllFilesExcept(string path, string exName)
        {
            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);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取指定路径下一层的指定格式的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        static public List <string> GetSubFiles(string path, string exName)
        {
            List <string> names = new List <string>();

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

            if (string.IsNullOrEmpty(exName) == true)
            {
                needCheck = false;
            }
            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 (needCheck == true && ex != exName)
                {
                    continue;
                }
                names.Add(StringTools.ChangePathFormat(files[i].FullName));
            }
            return(names);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取某目录下所有指定类型的文件的路径
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exName"></param>
        /// <returns></returns>
        static 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);
        }