Introducing file-sort - a dotnet global tool

Introducing file-sort - a dotnet global tool

I could as well use the title "Introducing Hello World - a dotnet global tool". file-sort is not some complicated utility, it's just a simple tool that I made in one night when I realized that instead of organizing thousands of photos manually I could just write my own tool. Sure, something that did this a lot better is just a google search away, but where's the fun in that?

file-sort was initially a C# console app, but a few months ago when I read about dotnet global tools I thought I could convert it into one and share it with the world. After a lot of delays, I finally made some time and published it on Nuget, and here's the process.

Creating a basic dotnet tool

Switching from a .NET Framework console app to a .NET Core app was really simple because in my case I could reuse 100% of the code. I just had to create a new .NET Core console app and move the logic in there.

Next, I had to transform the console app into a dotnet tool. Microsoft has a nice tutorial for this, it's basically just adding some info to your .csproj and then you're ready to run it locally. Here's how my .csproj looks like:

Before being able to run your console app as a dotnet tool you need to do two things. First, you have to pack it in a .nupkg, and then you have to install it. I created a .bat file to make this easier because after each build I would uninstall and reinstall the tool.

Using the tool

Here's a basic example of how it works:

file-sort -i=day

file-sort is the name of my tool, and the rest are arguments. In this case, I'm telling it to sort files by day. So if you have a folder full of pictures and you want to sort them by day, it will do just that.
You could also sort your pictures by years, months and days, just by using it like this:

file-sort -i=day -u

The -u flag allows it to use multiple classifiers. So it will go from the highest classifier(year) to the one you specified(day) and sort them like that. The lowest classifier is "hour", but I only used it once when I wanted to get all the photos from an event that happened at a specific time. I usually sort my "Camera Uploads" folder from Dropbox with this, and I set it to arrange my pictures by years and months. This is how my Dropbox "Photos" folder looks like:

image-24.png

image-25.png

image-26.png

If you think this is useful for you, go ahead and install it from NuGet using this command:

dotnet tool install --global file-sort

I know that it doesn't do much, but in the future, I want to add other classifiers, not just date. For example, I could tell it to filter all the photos with my face using Azure Cognitive Services, or I could organize them by location, etc. If you have any ideas and want to contribute to this tool, clone the repo and submit a PR or an issue, I'll be happy to review it!

Did you find this article valuable?

Support Bogdan Bujdea by becoming a sponsor. Any amount is appreciated!