public static void LISTDIRECTORY(TCPClient requester, string dir) { DirectoryInfo dirinfo; if (dir.Length != 2) { dirinfo = new DirectoryInfo(dir); } else { dirinfo = new DirectoryInfo(dir + "\\"); } FileInfo[] files = null; DirectoryInfo[] dirs = null; List <string> dnames = new List <string>(); try { files = dirinfo.GetFiles(); dirs = dirinfo.GetDirectories(); } catch { Log($"Access to directory '" + dir + "' was denied!", Color.Red); var pkg = new TcpPackage("ACCESS DENIED"); Log($"Begin send command response to client {{Host: {requester.Ip} Port: {requester.Port}}} - Length: {pkg.Size} byte(s)", Color.FromArgb(0x0072ff)); requester.SendPackage(pkg); Log($"Sent package to client {{Host: {requester.Ip} Port: {requester.Port}}} - Pacakge of System.byte[{pkg.Size}]", Color.Cyan); console.Log(""); return; } string data = "Files:"; if (new DirectoryInfo(dir).Parent != null && dir.Length != 2) { dnames.Add(".."); } foreach (var d in dirs) { if (!Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(d.Name)).Contains("?")) { dnames.Add(d.Name); } } for (int i = 0; i < files.Length; i++) { data += "\n\t" + files[i].Name + ";"; } data += "\nDirectories:"; for (int i = 0; i < dnames.Count; i++) { data += "\n\t" + dnames[i] + ";"; } var package = new TcpPackage(data); Log($"Begin send command response to client {{Host: {requester.Ip} Port: {requester.Port}}} - Length: {package.Size} byte(s)", Color.FromArgb(0x0072ff)); requester.SendPackage(package); Log($"Sent package to client {{Host: {requester.Ip} Port: {requester.Port}}} - Pacakge of System.byte[{package.Size}]", Color.Cyan); console.Log(""); }