| 1234567891011121314151617181920212223242526272829303132333435 |
- import fs from 'fs';
- import path from 'path';
- import { fileURLToPath } from 'url';
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = path.dirname(__filename);
- const testDir = path.join(__dirname, 'static', '漫画', 'image', '鬼-巷第001卷', '第一章', 'test');
- if (fs.existsSync(testDir)) {
- const files = fs.readdirSync(testDir);
- let deletedCount = 0;
-
- files.forEach(file => {
- const filePath = path.join(testDir, file);
- try {
- const stat = fs.statSync(filePath);
- if (stat.isDirectory()) {
- fs.rmSync(filePath, { recursive: true, force: true });
- console.log(`✅ 已删除文件夹: ${file}`);
- deletedCount++;
- } else {
- fs.unlinkSync(filePath);
- console.log(`✅ 已删除文件: ${file}`);
- deletedCount++;
- }
- } catch (error) {
- console.error(`❌ 删除失败: ${file} - ${error.message}`);
- }
- });
-
- console.log(`\n✅ 已清空test文件夹 (共删除 ${deletedCount} 项)`);
- } else {
- console.log('⚠️ test文件夹不存在,无需清空');
- }
|