本文介绍了如何从FTP文件列表中删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试获取.net中FTP目录中的文件列表,我在文件名./&之前得到以下字符。 vbCr& ../& vbCr&
如何才能获得前面没有这些字符的文件名列表?
这是阅读结束后返回的内容
./& vbCrLf&../& vbCrLf&filename.xlsx& vbCrLf&
我尝试过:
I am currently trying to get list of files in an FTP directory in .net and i am getting the following characters before the name of the files "./" & vbCr & "../" & vbCr & "
how do i get just the listing of the file names without these characters in front?
This is what is being returned after reading to end
"./" & vbCrLf & "../" & vbCrLf & "filename.xlsx" & vbCrLf & ""
What I have tried:
Dim Request As FtpWebRequest
Dim Response As FtpWebResponse
Request = DirectCast(FtpWebRequest.Create(FtpFolderPath), FtpWebRequest)
Request.Credentials = New NetworkCredential(UserName.Normalize, Password.Normalize)
Request.Proxy = Nothing
Request.Method = WebRequestMethods.Ftp.ListDirectory
Request.UseBinary = True
Response = DirectCast(Request.GetResponse(), FtpWebResponse)
Dim reader As New StreamReader(Response.GetResponseStream())
Dim Data As String = reader.ReadToEnd()
Data = Data.Replace(vbCrLf, vbCr).TrimEnd(Chr(13))
reader.Close()
Response.Close()
Return Data.Split(ControlChars.Lf)
推荐答案
Dim Data As String = reader.ReadToEnd().Replace("./" & vbCrLf & "../" & vbCrLf, "")
这篇关于如何从FTP文件列表中删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!