winure/qdls/Program.cs

42 lines
958 B
C#

using System.IO;
string[] arguments;
if(args.Length == 0)
arguments = ["."];
else
arguments = args;
foreach(var arg in arguments) {
if(!Path.Exists(arg))
Console.WriteLine($"'{arg}: does not exist");
if(File.Exists(arg))
Console.WriteLine($"'{arg}: is file");
var children = Directory.GetFileSystemEntries(arg);
var line = "";
var longest = children.OrderByDescending(s => Path.GetFileName(s).Length).First().Length;
var columns = Console.WindowWidth / (longest + 2);
var position = -1;
if(args.Length > 1)
Console.WriteLine($"{arg}:");
foreach(var child in children) {
var name = Path.GetFileName(child);
if(
name.StartsWith('.') ||
( File.GetAttributes(child) & FileAttributes.Hidden ) == FileAttributes.Hidden
)
continue;
if(++position >= columns) {
position = -1;
Console.WriteLine(line);
line = "";
}
line += name + " ";
}
Console.WriteLine(line);
}