clear-test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import fs from 'fs';
  2. import path from 'path';
  3. import { fileURLToPath } from 'url';
  4. const __filename = fileURLToPath(import.meta.url);
  5. const __dirname = path.dirname(__filename);
  6. const testDir = path.join(__dirname, 'static', '漫画', 'image', '鬼-巷第001卷', '第一章', 'test');
  7. if (fs.existsSync(testDir)) {
  8. const files = fs.readdirSync(testDir);
  9. let deletedCount = 0;
  10. files.forEach(file => {
  11. const filePath = path.join(testDir, file);
  12. try {
  13. const stat = fs.statSync(filePath);
  14. if (stat.isDirectory()) {
  15. fs.rmSync(filePath, { recursive: true, force: true });
  16. console.log(`✅ 已删除文件夹: ${file}`);
  17. deletedCount++;
  18. } else {
  19. fs.unlinkSync(filePath);
  20. console.log(`✅ 已删除文件: ${file}`);
  21. deletedCount++;
  22. }
  23. } catch (error) {
  24. console.error(`❌ 删除失败: ${file} - ${error.message}`);
  25. }
  26. });
  27. console.log(`\n✅ 已清空test文件夹 (共删除 ${deletedCount} 项)`);
  28. } else {
  29. console.log('⚠️ test文件夹不存在,无需清空');
  30. }