Recursive file counting

- Posted in Coding by
using System;
using System.Reflection;
using System.IO;

namespace GetFilesRecursively {
class Program {

    static void Main(){
        int cnt = 0;
        long bites = 0;
        string p = string.Empty;
        foreach (string file in System.IO.Directory.GetFiles(
            GetExecutingDirectoryName(), "*",SearchOption.AllDirectories))
        {
            cnt++;
            FileInfo fi = new FileInfo(file);
            bites += fi.Length;
            //do something with file
            p = String.Format("{0:n0}", (int)bites);
        }   
        Console.Write(" Total files: {0}, ", cnt.ToString());
        Console.WriteLine("totaling {0} bytes.", p);
    }

    /* found following method here: 
    https://www.red-gate.com/simple-talk/blogs/c-getting-
    the-directory-of-a-running-executable/ */
    public static string GetExecutingDirectoryName()
    {
        var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase);
        return new FileInfo(location.AbsolutePath).Directory.FullName;
    }       
  }
}

A php script to count Flatpress blog entries

- Posted in Coding by

I wrote a custom page in PHP to count the number of blog entries I have made, on a Flatpress self-hosted blog.

I've updated the script to work on my 2023 HTMLy blog, but the original script was for Flatpress.

We went tonight for revival meeting. Richie Coomer, a former middle school teacher of mine, was the preacher. Followed that upon getting home with three episodes of Money Heist.

Count top-level subdirectories

- Posted in Coding by

C# get number of top-level subdirectories in a directory.

Here's a brief program that demonstrates counting the number of top-level subdirectories that reside within a given directory:

https://gist.github.com/kyrathasoft/1dc1a1eb4d6a2a56827dcb5f43840afe