!!!重赏之下必有勇夫,求教c# ftp如何判断目录下取出来的东西是文件还是文件夹!!!

大黄鸭在发光 大黄鸭在发光 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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分啊!
...全文
评论 14
收藏 已收藏
分享
返回顶部
大黄鸭在发光
C# 111,130 成员 642,539 内容