日期:2014-05-17  浏览次数:21146 次

Directory.GetFiles();参数问题
Directory.GetFiles();参数问题,我想同时获取指定文件夹下的两种文件,比如:*.txt,和*.doc,应该怎样加才行,我现在在第二个参数中只能获取一种类型的文件,请帮忙............

------解决方案--------------------
分别取
  
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 

http://feiyun0112.cnblogs.com/
------解决方案--------------------
GetFiles(string) 返回的时FileInfo[]类型的数据,你可以定义两个FileInfo[]对象来取文件,最后从这两个FileInfo[]中取你取到的文件,[呵呵一个变通的方法]
------解决方案--------------------
String ExtName = Path.GetExtension(UploadFileName);
if (ExtName == ".doc")
typeID = 3;
else if (ExtName == ".xls")
typeID = 4;
else if (ExtName == ".ppt")
typeID = 5;
else if (ExtName == ".mdb")
typeID = 6;
else if (ExtName == ".htm" || ExtName == ".html")
typeID = 7;
else if (ExtName == ".gif")
typeID = 8;
else if (ExtName == ".rar")
typeID = 9;
else if (ExtName == ".txt")
typeID = 10;
else if (ExtName == ".avi")
typeID = 11;
else if (ExtName == ".pdf")
typeID = 12;
else if (ExtName == ".exe")
typeID = 13;
else
typeID = 2;
Int32 size = this.FileUpload1.PostedFile.ContentLength;
if (size <= 250 * 1024)
{
//String SavePath = this.labFilePath.Text;
String SavePath = Server.MapPath("~/FileUpload");
String SaveFileName = SavePath + "\\" + Path.GetFileName(UploadFileName);
this.FileUpload1.SaveAs(SaveFileName);
------解决方案--------------------
探讨
String ExtName = Path.GetExtension(UploadFileName);
if (ExtName == ".doc")
typeID = 3;
else if (ExtName == ".xls")
typeID = 4;
else if (ExtName == ".ppt")
typeID = 5;
else if (ExtName == ".mdb")
typeID = 6;
else if (ExtName == ".htm" || ExtName == ".html")…

------解决方案--------------------
lz 可以试试这么做

C# code
        private ArrayList GetFiles(string sPath, string[] sPt) //sPath是路径,sPt是文件后缀的数组
        {
            DirectoryInfo dir = new DirectoryInfo(sPath);
            ArrayList Files = new ArrayList();
            FileInfo[] tmp;

            foreach (string s in sPt)
            {
                tmp = dir.GetFiles(s);
                foreach (FileInfo fi in tmp)
                {
                    Files.Add(fi);
                }
            }
            return Files;
        }