public string[] GetFileList()
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpPath + "/"));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(username,
password);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response
.GetResponseStream()); string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
return result.ToString().Split('\n');
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
downloadFiles = null;
return downloadFiles;
}
}这是我的代码,其功能是获得ftp目录下的所有文件和文件夹。返回进string数组。
现在我想问遍历返回的这个数组时如何判断其内容是一个文件还是文件夹。
不要说判断名字有没有“.”,这个不好。谢谢大家。200分啊!
解决方案 »
- ◆vs2010 winform 水晶报表 如何给未绑定字段UnboundString赋值◆
- 无法读取配置节“system.web.extensions”,因为它缺少节声明。帮顶有分。
- 用C#可以做工控机的程序么?
- 简单的问题,请教大家
- 如何用.net编程隐藏另一个正在运行的应用程序的窗口
- 关于webBrowser使用代理的问题
- 简单问题,请进
- 200分问一个DataSet merge 问题
- 一个类的两个实例A和B 把A=B,改变A里的某字段而不使B中的相应字段被改变,在线!
- WCF android 以及winform交互问题
- ArrayList中添加结构体
- 带加密狗的exe文件,怎么在线升级?
http://topic.csdn.net/u/20080130/23/d65b981a-5d14-4898-9bff-c39bed18a7eb.html
这里面的就够你用的了。判断一下dir就可以了
if ((fileInfo.Attributes & FileAttributes.Directory) != 0){//目录}else{//文件}