Esempio n. 1
0
    public static void Demo_Dir_Walk_Simple(string path)
    {
        Console.WriteLine("\n--------------- Chapter 1.5 Dir_Walk_Simple ---------------");
        Dir_Walk_Simple(path, Print_Dir);
        Console.WriteLine();

        // dir-walk-simple called with lambdas - Higher Order Perl p. 19
        Console.WriteLine("\n--------------- Chapter 1.5 Dir_Walk_Simple w/ lambda ---------------");
        // Same as Print_Dir, but using an expression lambda
        Dir_Walk_Simple(path, (x) => Console.WriteLine(x));
        Console.WriteLine();

        Console.WriteLine("\n--------------- Chapter 1.5 Dir_Walk_Simple w/ sizes ---------------");
        Dir_Walk_Simple(path, (x) => Console.WriteLine(DirOrFileSizeFormat, PerlFileOps.Size(x), x));
        Console.WriteLine();

        Console.WriteLine("\n--------------- Chapter 1.5 Dir_Walk_Simple that displays Broken Links/Shortcuts ---------------");
        Dir_Walk_Simple(path, (x) =>
        {
            if (PerlFileOps.Link(x, out string target) && !PerlFileOps.Exists(target))    // -l && -e
            {
                Console.WriteLine("'{0}' => '{1}'", x, target);
            }
        });
        Console.WriteLine();

        // dir-walk-simple used with an accumulator in the lambda - Higher Order Perl p. 20
        Console.WriteLine("\n--------------- Chapter 1.5 Dir_Walk_Simple w/ total size ---------------");
        long total = 0;

        Dir_Walk_Simple(path, (x) => total += PerlFileOps.Size(x));
        Console.WriteLine("Total size of '{0}' is {1:N0}", path, total);
        Console.WriteLine();
    }
Esempio n. 2
0
 // dangles example
 public static object Dangles(string file)
 {
     if (PerlFileOps.Link(file, out string target) && !PerlFileOps.Exists(target))    // -l && -e
     {
         Console.WriteLine("'{0}' => '{1}'", file, target);
     }
     return(null);
 }
Esempio n. 3
0
    public override void FileOrDirectory(string path)
    {
        string target;

        if (PerlFileOps.Link(path, out target) && !PerlFileOps.Exists(target))    // -l && -e
        {
            Console.WriteLine("'{0}' => '{1}'", path, target);
        }
    }
Esempio n. 4
0
 public override object File(string path)
 {
     if (PerlFileOps.Exists(path))
     {
         return(PerlFileOps.Size(path));
     }
     else
     {
         Console.WriteLine("'{0}' - no such file or directory exists.", path);
         return(0);
     }
 }