/// <summary> /// Parse directory item from Windows-Style record. /// </summary> /// <param name="record"></param> /// <returns></returns> private DirItemStruct ParseFileStructFromWindowsStyleRecord(string record) { // Assuming the record style as // 02-03-04 07:46PM <DIR> Append var f = new DirItemStruct(); string processstr = record.Trim(); string dateStr = processstr.Substring(0, 8); processstr = (processstr.Substring(8, processstr.Length - 8)).Trim(); string timeStr = processstr.Substring(0, 7); processstr = (processstr.Substring(7, processstr.Length - 7)).Trim(); f.CreateTime = DateTime.ParseExact(dateStr + " " + timeStr, "MM-dd-yy h:mmtt", CultureInfo.InvariantCulture); if (processstr.Substring(0, 5) == "<DIR>") { f.IsDirectory = true; processstr = (processstr.Substring(5, processstr.Length - 5)).Trim(); } else { string[] strs = processstr.Split(new[] { ' ' }, StringSplitOptions.None); processstr = strs[1].Trim(); f.IsDirectory = false; } f.Name = processstr; //Rest is name return(f); }
/* * Code for parsing FtpwebRequest response for ListDirectoryDetails * http://blogs.msdn.com/b/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx */ /// <summary> /// Parse raw output from <see cref="WebRequestMethods.Ftp.ListDirectoryDetails"/> /// into <see cref="DirItemStruct"/> /// </summary> /// <param name="dirItems"></param> /// <returns></returns> private IEnumerable <DirItemStruct> GetDirItemsParsed(IList <string> dirItems) { var retval = new List <DirItemStruct>(); DirItemListStyle directoryListStyle = GuessFileListStyle(dirItems); foreach (string s in dirItems) { if (directoryListStyle != DirItemListStyle.Unknown && s != "") { var f = new DirItemStruct { Name = ".." }; switch (directoryListStyle) { case DirItemListStyle.UnixStyle: f = ParseFileStructFromUnixStyleRecord(s); break; case DirItemListStyle.WindowsStyle: f = ParseFileStructFromWindowsStyleRecord(s); break; } if (!(f.Name == "." || f.Name == "..")) { retval.Add(f); } } } return(retval.ToArray());; }
/// <summary> /// Parse directory item from Windows-Style record. /// </summary> /// <param name="record"></param> /// <returns></returns> private DirItemStruct ParseFileStructFromWindowsStyleRecord(string record) { // Assuming the record style as // 02-03-04 07:46PM <DIR> Append var f = new DirItemStruct(); string processstr = record.Trim(); string dateStr = processstr.Substring(0, 8); processstr = (processstr.Substring(8, processstr.Length - 8)).Trim(); string timeStr = processstr.Substring(0, 7); processstr = (processstr.Substring(7, processstr.Length - 7)).Trim(); f.CreateTime = DateTime.ParseExact(dateStr + " " + timeStr, "MM-dd-yy h:mmtt", CultureInfo.InvariantCulture); if (processstr.Substring(0, 5) == "<DIR>") { f.IsDirectory = true; processstr = (processstr.Substring(5, processstr.Length - 5)).Trim(); } else { string[] strs = processstr.Split(new[] {' '}, StringSplitOptions.None); processstr = strs[1].Trim(); f.IsDirectory = false; } f.Name = processstr; //Rest is name return f; }
/* * Code for parsing FtpwebRequest response for ListDirectoryDetails * http://blogs.msdn.com/b/adarshk/archive/2004/09/15/sample-code-for-parsing-ftpwebrequest-response-for-listdirectorydetails.aspx */ /// <summary> /// Parse raw output from <see cref="WebRequestMethods.Ftp.ListDirectoryDetails"/> /// into <see cref="DirItemStruct"/> /// </summary> /// <param name="dirItems"></param> /// <returns></returns> private IEnumerable<DirItemStruct> GetDirItemsParsed(IList<string> dirItems) { var retval = new List<DirItemStruct>(); DirItemListStyle directoryListStyle = GuessFileListStyle(dirItems); foreach (string s in dirItems) { if (directoryListStyle != DirItemListStyle.Unknown && s != "") { var f = new DirItemStruct {Name = ".."}; switch (directoryListStyle) { case DirItemListStyle.UnixStyle: f = ParseFileStructFromUnixStyleRecord(s); break; case DirItemListStyle.WindowsStyle: f = ParseFileStructFromWindowsStyleRecord(s); break; } if (!(f.Name == "." || f.Name == "..")) { retval.Add(f); } } } return retval.ToArray(); ; }