首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Directory.GetFiles();参数有关问题

2012-10-20 
Directory.GetFiles()参数问题Directory.GetFiles()参数问题,我想同时获取指定文件夹下的两种文件,比如:

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;        } 

热点排行