Exemplo n.º 1
0
    public override void Main(string[] arguments)
    {
        var dirPath = Environment.CurrentDirectory;

        if (arguments.Length > 0)
        {
            dirPath = Path.GetFullPath(arguments[0]);
        }

        var dir = Directory.GetDirEntry(dirPath);

        if (!dir.Exists)
        {
            throw new Error("directory '" + dir.FullName + "' doesnt exist");
        }

        var ecma48 = new StdLib.Ecma48.Client(Console.Out);

        ecma48.ResetAttributes();

        int counter = 0;

        foreach (var d in dir.EnumerateDirectories())
        {
            counter++;
            ecma48.SetForegroundColor(StdLib.Ecma48.Color.Default);
            Console.Write(d.CreationTime + "  " + d.LastWriteTime);
            ecma48.SetForegroundColor(StdLib.Ecma48.Color.Cyan);
            Console.WriteLine("  D  " + d.Name);
        }
        foreach (var f in dir.EnumerateFiles())
        {
            counter++;
            ecma48.SetForegroundColor(StdLib.Ecma48.Color.Default);
            Console.Write(f.CreationTime + "  " + f.LastWriteTime);
            ecma48.SetForegroundColor(StdLib.Ecma48.Color.Green);
            Console.WriteLine("  F  " + f.Name);
        }
        if (counter == 0)
        {
            Console.WriteLine("'" + dir.FullName + "' is empty");
        }

        ecma48.ResetAttributes();
    }