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.4 – C++ – Safe File Movement and User Feedback

Posted on 12 Ottobre 202512 Ottobre 2025 By Francesco

“Power means nothing if your user can’t trust it.”

By now, our File Organizer knows how to identify file types and create folders.
The final step is what makes or breaks the whole project — moving files safely and communicating clearly.

Because a program that touches personal files must feel predictable, reversible, and respectful.
This is where WoW begins — not in clever code, but in thoughtful interaction.


4.1 Safety Is a Feature, Not an Option

When you build tools that move, rename, or delete, the rule is simple:
never surprise the user.

That means:

  1. No silent overwrites.
  2. Clear logs of what happened.
  3. Recovery paths (backups or renames).
  4. Friendly, human-readable feedback.

This mindset turns automation into trust.


4.2 Building the Foundation — Logging and Feedback

Before touching anything, let’s give ourselves eyes and memory — a log file and a timestamp.

#include <iostream>
#include <filesystem>
#include <fstream>
#include <chrono>
#include <iomanip>

namespace fs = std::filesystem;

void logAction(const std::string& message) {
std::ofstream log("organizer.log", std::ios::app);
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
log << std::put_time(std::localtime(&now), "%Y-%m-%d %H:%M:%S")
<< " - " << message << "\n";
}

Each action will now be both visible and recorded.
Even if something fails, you’ll always know why.


4.3 Moving Files Safely

A single careless rename() can destroy hours of work.
Let’s do it the right way — with checks, backups, and transparent reporting.

bool moveFileSafely(const fs::path& src, const fs::path& dstFolder) {
if (!fs::exists(src) || !fs::is_regular_file(src)) {
std::cerr << "⚠️ Skipping invalid file: " << src.filename() << "\n";
logAction("Skipped invalid file: " + src.string());
return false;
}

fs::path destination = dstFolder / src.filename();

if (fs::exists(destination)) {
    auto stem = destination.stem().string();
    auto ext  = destination.extension().string();
    int counter = 1;
    do {
        destination = dstFolder / (stem + "_" + std::to_string(counter++) + ext);
    } while (fs::exists(destination));
    std::cout << "🧩 Duplicate detected, renaming to: "
              << destination.filename() << "\n";
}

try {
    fs::rename(src, destination);
    std::cout << "✅ " << src.filename() << " → " << destination << "\n";
    logAction("Moved " + src.string() + " → " + destination.string());
    return true;
} catch (const fs::filesystem_error& e) {
    std::cerr << "❌ Error moving " << src.filename()
              << ": " << e.what() << "\n";
    logAction("Error moving " + src.string() + ": " + e.what());
    return false;
}

4.4 Testing the Move

Let’s connect it to the main routine and see it work. 
int main() {
fs::path desktop = "C:/Users/Francesco/Desktop";
fs::path images = desktop / "Images";
fs::path docs = desktop / "Documents";

Console Output:

fs::create_directories(images);
fs::create_directories(docs);

int successCount = 0, failCount = 0;

for (const auto& entry : fs::directory_iterator(desktop)) {
    if (!entry.is_regular_file()) continue;

    auto ext = entry.path().extension().string();
    if (ext == ".jpg" || ext == ".png") {
        successCount += moveFileSafely(entry.path(), images);
    } else if (ext == ".pdf" || ext == ".docx") {
        successCount += moveFileSafely(entry.path(), docs);
    } else {
        std::cout << "🔹 Skipping: " << entry.path().filename() << "\n";
        failCount++;
    }
}

std::cout << "\nSummary:\n";
std::cout << " - Files moved successfully: " << successCount << "\n";
std::cout << " - Files skipped or failed:  " << failCount << "\n";
std::cout << "---------------------------------------\n";
std::cout << "✨ Organization complete. Enjoy your clean desktop!\n";

Console output example:

Duplicate detected, renaming to: report_1.pdf
report.pdf → Documents
photo.jpg → Images
Skipping: desktop.ini
Files moved successfully: 2

Files skipped or failed: 1
Organization complete. Enjoy your clean desktop!

Now every action leaves a trace — not for control, but for confidence.


4.5 Dry Run Mode — Safety Before Speed

Before moving any files, users can preview what would happen.
This is one of the simplest but most powerful safety features you can add.

bool dryRun = true; // toggle this

if (dryRun) {
std::cout << "Would move: "
<< src.filename() << " → " << destination << "\n";
logAction("Preview: " + src.string() + " → " + destination.string());
return true;
}

Would move: budget.xlsx → Documents\budget.xlsx
Would move: logo.png → Images\logo.png

Dry-Run Output:

Would move: budget.xlsx → Documents\budget.xlsx
Would move: logo.png → Images\logo.png

The result: the user feels in control — not surprised.


4.6 Extra Layer — Automatic Backup

A professional touch: before performing the first move, copy all original files to a “Backup” folder.

void backupFolder(const fs::path& source, const fs::path& backup) {
fs::create_directories(backup);
for (const auto& entry : fs::directory_iterator(source)) {
if (!entry.is_regular_file()) continue;
fs::path target = backup / entry.path().filename();
if (!fs::exists(target)) {
fs::copy(entry.path(), target);
std::cout << "🗂️ Backed up: " << entry.path().filename() << "\n";
}
}
}

Usage:

backupFolder(desktop, desktop / "Backup");

Because even perfect programs deserve a safety net.


4.7 Human Feedback Matters

C++ can sometimes feel “cold” — precise, logical, silent.
But a good user experience is about tone, not syntax.

  • Use symbols (✅ ⚠️ ❌ ✨) for instant readability.
  • Write short, clear sentences.
  • Provide closure at the end (“All files organized successfully.”).
  • Log with real timestamps, not generic “Done.”

These details make your tool pleasant to use.
The difference between script and software is emotional quality.


4.8 Going Further — Progress Indicators

For large folders, you can show progress with a simple counter:

int total = std::distance(fs::directory_iterator(desktop),
fs::directory_iterator());
int current = 0;

for (const auto& entry : fs::directory_iterator(desktop)) {
++current;
std::cout << "[" << current << "/" << total << "] "
<< entry.path().filename() << "\n";
// move logic...
}

[1/15] report.pdf
[2/15] photo.jpg
[3/15] notes.txt

Output:

15 files processed in 1.4 s

Even minimal progress feedback turns waiting into understanding.


4.9 The “WoW” Moment

When you run it, something changes:
your desktop looks clean, your console looks professional,
and your brain feels lighter.

That’s the WoW — realizing that even in C++,
you can design with empathy, not just with efficiency.

Performance is only half the story. The other half is trust.
A program that respects user data earns the right to be fast.

This is how modern C++ reclaims its humanity — not by abstracting everything, but by caring deeply about what it does.

Post Views: 362

Condividi:

  • Condividi su Facebook (Si apre in una nuova finestra) Facebook
  • Condividi su X (Si apre in una nuova finestra) X
Coding C++ Form Zero to "WoW" c++C++ filesystem tutorialC++17 filesystemclean codeconsole UXfile organizerfilesystem error handlingFrom Zero to WoWmove files safely

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

Go

Coding – Step 12.3 – Go from Zero to “WoW” – Smart Filtering & Display Logic

Posted on 7 Ottobre 20257 Ottobre 2025

Build a tiny but powerful Go CLI that loads items, filters them with composable predicates, and prints a clean table. You’ll learn how to model data, write reusable filter functions, chain conditions, sort and paginate results, and test everything with Go’s testing tools.

Condividi:

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

I built MyTracker: a minimal time tracker to work better

Posted on 14 Ottobre 202514 Ottobre 2025

MyTracker is a minimal time tracker I built to remove friction: start an activit

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 14.7 – Ubuntu – User Management & System Security — “The Cathedral of Permissions”

Posted on 29 Ottobre 202529 Ottobre 2025

Discover how Ubuntu protects itself from the inside. Learn to create users, assign roles, and control permissions like a true system architect — where every command shapes trust and responsibility.

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