node.js - Node.js completely remove file in a running script
问题描述
I have a Node.js
script that is running in a while (true)
fashion and watches directories for certain files and removes them using unlink
API
:
fs.unlinkSync(path);
The files are not created by Node
process, but as POSIX
documentation about unlink
says, files are not removed from disk until process is closed, thus lsof
will list them as (deleted)
and tied to node
process.
My script is some kind of a "watchdog"
, so how would I go to removing those files and cleaning up disk space without restarting the Node
process itself?
Thanks!
解决方案
我会尝试child_process
:
const { execSync } = require('child_process');
execSync(`rm ${filePath}`)
推荐阅读
- c++ - How can I pass a condition to a function in C++?
- google-app-engine - 如何在 GCP App Engine Flex 中将特定端点设为私有或至少受限制?
- java - 需要在 FileNameFilter 接口的 lambda 表达式中构造文件实例
- python - 如何将多个复选框数据存储在数组列表中?
- android - 我在搅拌机中制作了一个 3d 模型并想在 android 应用程序项目中使用它?
- sql - SQL 在视图中添加 JOIN 子句
- javascript - Javascript 正则表达式:如何删除与 | 之后的任何文本匹配的 JSON 值 包含?
- sql - BigQuery 从嵌套数组中选择和别名字段而不分组
- java - Servlet 无法获取输入
- python - Pandas 函数输出不正确,不知道如何。oconus_days1 row = 25 应该是 20,怎么了?