[英]How can i make an application using Node.js, which can separate all the files with same extension?
Something like this will work.像这样的东西会起作用。 Using
fs
module and path
module使用
fs
模块和path
模块
Which will first check the extension and rename file (move) to new folder.这将首先检查扩展名并将文件重命名(移动)到新文件夹。
You can make changes accordingly.您可以进行相应的更改。 Use
if
使用
if
const testFolder = './';
const fs = require('fs');
var path = require('path')
var oldPath = 'old/path/file.txt'
var newPath = 'new/path/file.txt'
fs.readdir(testFolder, (err, files) => {
files.forEach(file => {
const ext = path.extname(file);
fs.rename(oldPath, newPath, function (err) {
if (err) throw err
console.log('Successfully renamed - AKA moved!')
})
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.