文件操作 - del.js
返回文件管理
返回主菜单
删除本文件
文件: /var/www/OLD/node_modules/flat-cache/src/del.js
编辑文件内容
const fs = require('fs'); const path = require('path'); function del(targetPath) { if (!fs.existsSync(targetPath)) { return false; } try { if (fs.statSync(targetPath).isDirectory()) { // If it's a directory, delete its contents first fs.readdirSync(targetPath).forEach(file => { const curPath = path.join(targetPath, file); if (fs.statSync(curPath).isFile()) { fs.unlinkSync(curPath); // Delete file } }); fs.rmdirSync(targetPath); // Delete the now-empty directory } else { fs.unlinkSync(targetPath); // If it's a file, delete it directly } return true; } catch (error) { console.error(`Error while deleting ${targetPath}: ${error.message}`); } } module.exports = { del };
修改文件时间
将文件时间修改为当前时间的前一年
删除文件