Parsing FtpWebRequest ListDirectoryDetails line

Not sure if you still need this, but this is the solution i came up with:

Regex regex = new Regex ( @"^([d-])([rwxt-]{3}){3}\s+\d{1,}\s+.*?(\d{1,})\s+(\w+\s+\d{1,2}\s+(?:\d{4})?)(\d{1,2}:\d{2})?\s+(.+?)\s?$",
    RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace );

Match Groups:

  1. object type:
    • d : directory
    • – : file
  2. Array[3] of permissions (rwx-)
  3. File Size
  4. Last Modified Date
  5. Last Modified Time
  6. File/Directory Name

Leave a Comment