electron node 移除删除文件至win回收站
要将文件移动到Windows回收站,可以使用第三方模块"trash"。
首先需要安装"trash"模块:
npm install trash
然后,可以使用以下代码将文件移动到回收站:
const fs = require('fs');
const trash = require('trash');
const filePath = 'path/to/file';
// 检查文件是否存在
if (fs.existsSync(filePath)) {
// 移动文件到回收站
trash(filePath).then(() => {
console.log('文件已移动到回收站');
}).catch((err) => {
console.error(err);
});
} else {
console.log('文件不存在');
}
这将使用"trash"模块将指定的文件移动到Windows回收站中。请注意,此方法仅适用于Windows系统。在其他操作系统上,文件可能会被永久删除而不是移动到回收站
原文地址: https://www.cveoy.top/t/topic/ei5y 著作权归作者所有。请勿转载和采集!