Skip to content
This is my space, where experience meets the will to start over. This is my space, where experience meets the will to start over.

The first step is knowing where you want to go.

  • Home
  • Coding Hub
    • Software & Project
      • Small Biz Ops – S.B.O.
        • SmallBizOps – Day 10/90
      • CRM/ERP
      • MyTracker
      • My Budget
    • Form Zero to “WoW”
      • JavaScript from Zero (Completed)
        • 2. Remove and Edit List Items
        • 3. Separate HTML and JavaScript, Use addEventListener and Conditional Logic
        • 4. Add Dynamic CSS Classes
        • 5. Save & Restore Your List with localStorage
        • 6 – Turn Your App into a Full To-Do List
      • Python from Zero (Completed)
        • 2. Lists & Loops
        • 3. Conditional Menus
        • 4. Edit & Remove Tasks (with closing: Python vs PHP and Large Data)
        • 5 – Save to File: Make Your Tasks Survive Restarts
        • 6 — Pythin from zero – Final Project Polishing: Numbering, Formatting, and Preparing for CSV
      • Rust – From Zero to “WoW” (Completed)
        • 1 – Setup and Project Structure in Rust
        • 2 – User input: validation and error handling
        • 3 – Rust from Zero to “WoW – BMI Calculation and Conditional Logic
        • 4 –Rust – Clear, Formatted Output
        • 5 – Rust – Final Thoughts: Precision as a Form of Respect
      • Go from Zero to “WoW” (Completed)
        • 1 – Why Go Is Perfect for a Personal Expense Tracker
        • 2 – Logging Expenses and Console Input
        • 3 – Go from Zero to “WoW” – Smart Filtering & Display Logic
        • 4 – Go – Saving Data to Local Files
        • 5 – Go – Final Project – Expense Tracker in Go
      • C++ from Zero to “WoW” (Completed)
        • 1 – Why C++ for file organization?
        • 2 – C++ – File Type Detection and Classification
        • 3 – C++ – Creating & Managing Subfolders
        • 4 – C++ – Safe File Movement and User Feedback
        • 5 – C++ – Order as Mental Clarity
      • Ubuntu – From Zero to “WoW” (Completed)
        • 2 – Ubuntu – The Desktop Environment and Essential Commands
        • 3 – Ubuntu – Managing Files, Folders, and Permissions
        • 4 – Ubuntu – Installing and Updating Software with APT and Snap
        • 5 – Ubuntu – Customizing the Desktop Environment
        • 6 – Ubuntu – Network and Device Configuration
        • 7 – Ubuntu – User Management & System Security — “The Cathedral of Permissions”
        • 8 – Ubuntu – The Talking Machine: Terminal & Bash Scripting
        • 9 – Ubuntu – Ubuntu as a Server or Development Environment
        • 10 – Ubuntu – Backup, Maintenance & Troubleshooting
    • Git Hub Repository
      • Small Biz Ops – S.B.O.
      • Mini ERP – PHP & MySQL
      • CleverCRM (Java, Spring Boot)
      • FraudWatch (Python, FastAPI + scikit-learn)
      • OnboardIQ – Smart Onboarding Portal (Flask + SQLite Demo)
    • ArchPilot
      • 1-Users & Roles, End-to-End (Architecture, Database, and Cross-Framework Code)
      • 2 – Client Registry (CRM) Across Frameworks
      • 3 – Project & Budget Tracker (ERP)
      • 4 – Approval Workflow Engine Multi-step routing, status tracking, escalation paths
      • 5 – Audit Trail & Versioning
    • Small Biz Ops – S.B.O.
  • Vivere in USA
  • P4Y
  • Testi poetici
    • 1 – Sospeso
    • 2 – Il bicchiere di vetro quieto
    • 3 – Quando l’amore inciampa
    • 4 – Ma chi siete davvero?
    • 5 – Above the Thread of Day
    • 6 – The Truth That Doesn’t Exist
    • 7 – All of You, I Miss
    • 8 – The Captain and the Ocean
    • 9 – Between Light and Mist
    • 10 – Il peso delle scelte
  • Contact
  • Admin
This is my space, where experience meets the will to start over.
This is my space, where experience meets the will to start over.

The first step is knowing where you want to go.

Coding – Step 13.2 – C++ from Zero to “WoW” – File Type Detection and Classification

Posted on 27 Settembre 202527 Settembre 2025 By Francesco

Organizing files manually can be frustrating. You open a folder, and it’s full of documents, images, videos, and random downloads all mixed together. Clicking through and dragging files one by one quickly becomes boring — and error-prone.

With C++17, we have a new ally: the <filesystem> library. It gives us the ability to look inside folders, check file names and extensions, and decide what belongs where. This is exactly what we need to build our file organizer.

In this chapter, we’ll learn:

  1. How to detect a file’s type by looking at its extension.
  2. How to group files into categories (e.g., Images, Docs, Videos).
  3. How to move them into the right subfolders safely.

The goal is not just to write some code, but to create the first real version of our organizer: a tool that takes a messy folder and shows order, clarity, and discipline.


Step 1 – Defining categories

Every file has an extension: .jpg, .pdf, .mp3, .zip …
By creating a simple map of extension → category, we can tell our program how to classify files.

Example:

  • .jpg, .png, .gif → Images
  • .pdf, .docx, .txt → Docs
  • .mp3, .wav → Audio
  • .zip, .rar → Archives
  • Anything unknown → Other

We’ll use an unordered_map in C++ to store this mapping.

#include <string>
#include <unordered_map>
#include <algorithm>

const std::unordered_map<std::string, std::string> EXT_TO_DIR = {
    {".jpg","Images"}, {".png","Images"}, {".gif","Images"},
    {".pdf","Docs"}, {".docx","Docs"}, {".txt","Docs"},
    {".mp3","Audio"}, {".wav","Audio"},
    {".zip","Archives"}, {".rar","Archives"}
};

This is just a start — you can expand the map whenever you want.


Step 2 – Scanning a folder

The <filesystem> library lets us scan a folder easily. For each file we find, we check its extension and decide the category.

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;

int main() {
    std::string path = "./folder_to_organize";

    for (const auto& entry : fs::directory_iterator(path)) {
        if (entry.is_regular_file()) {
            std::string ext = entry.path().extension().string();
            std::cout << "File: " << entry.path().filename()
                      << " | Extension: " << ext << std::endl;
        }
    }
    return 0;
}

Run this code and watch your folder being “listed.” You’ll see each file’s name and extension printed out.


Step 3 – Deciding where to move files

Once we know the extension, we look it up in our EXT_TO_DIR map:

std::string category = "Other";
auto it = EXT_TO_DIR.find(ext);
if (it != EXT_TO_DIR.end()) {
    category = it->second;
}

Now we know the category (like “Images” or “Docs”) and can decide where the file should go.


Step 4 – Moving files safely

Finally, we use <filesystem> to create a subfolder if it doesn’t exist, and then move the file there.

fs::path targetDir = path / category;
fs::create_directories(targetDir); // safe: does nothing if it already exists
fs::rename(entry.path(), targetDir / entry.path().filename());

Important: Always test on a copy of your files first. For extra safety, you can add a dry-run mode where the program only prints what it would do without actually moving anything.


End of Chapter Reflection

At this point, you’ve written a program that doesn’t just look at files — it starts to bring order into chaos. From a messy folder, you can automatically separate documents, images, and music with the press of a key.

For beginners, this is a big milestone: you’re not just printing “Hello World” anymore. You’re controlling your digital space with C++. That’s power, discipline, and the first real taste of automation.

Post Views: 256

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
C++ Coding automationbeginnersc++cpp17file organizationfilesystemProgramming

Navigazione articoli

Previous post
Next post

Francesco

My name is Francesco Boschi, originally from Italy and currently based in the United States. For over twenty years, I’ve worked as a manager and consultant across diverse sectors — from education and cultural institutions to the food industry — developing skills in operational management, strategic consulting, and complex problem-solving. In recent years, I’ve combined this experience with a strong passion for software development, creating custom tools designed to simplify workflows and meet real business needs.

Relocating to the U.S. marks the beginning of a new chapter: a personal and professional decision driven by the desire to be close to my son and to embrace new challenges in a different environment. Today, my goal is to turn my experience into meaningful solutions, blending strategic vision with technical expertise to help people and organizations work more effectively.

I enjoy moving between different worlds, adapting tools and approaches to people and contexts. I bring leadership, flexibility, attention to detail, analytical thinking, and a strong problem-solving mindset — along with a deep curiosity to learn and grow. Above all, I believe in sharing: I’m always eager to offer my experience to support the growth of others.

Related Posts

Coding

Coding – Step 10.4 – Edit & Remove Tasks (with closing: Python vs PHP and Large Data)

Posted on 17 Agosto 202517 Agosto 2025

Add edit and delete features to your Python To-Do app. Learn the differences between Python and PHP and how to approach large data.

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Read More
Coding

Coding – Step 9.5 – JavaScript from Zero – Save & Restore Your List with localStorage

Posted on 17 Agosto 202517 Agosto 2025

Persist your To-Do list in the browser using localStorage. Save on each change, reload on startup, and keep the UI accessible with ARIA.

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Read More
Javascript

Coding – Step 9.6 – Turn Your App into a Full To-Do List

Posted on 20 Agosto 202520 Agosto 2025

In Step 9.6 of our JavaScript from Zero course, we transform the app into a full-featured to-do list: add, edit, complete, delete tasks and save everything with localStorage.

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Read More

Iscriviti alla nostra Newsletter

🤞 Let's keep in touch

We do not send spam! Read our Privacy policy for more information.

Controlla la tua casella di posta o la cartella spam per confermare la tua iscrizione

Cerca nel sito

©2026 This is my space, where experience meets the will to start over. | WordPress Theme by SuperbThemes