下面是使用fs
var fs = require('fs'),
input_path = '/home/webapps/project1/folder1/',
output_path = '/home/webapps/project1/folder2/';
fs.readdir(input_path, function(err, files) {
var date = new Date();
date = ('0' + (date.getMonth()+1)).slice(-2) + ''
+ ('0' + date.getDate()).slice(-2) + ''
+ ('0' + (date.getFullYear())).slice(-2);
files.forEach(function(file) {
var name, extension;
// Check for *.CSV files
if (file.toLowerCase().indexOf('.csv') !== file.length - 4) return;
name = file.substr(0, file.length - 4);
extension = file.substr(-4);
// Copy file
fs.createReadStream(input_path + file).pipe(fs.createWriteStream(output_path + name + date + extension));
});
});
請訪問以下鏈接工作例如:http://stackoverflow.com/questions/29404104/javascript-automation-for-files-move-into-another-folder – BlackMamba 2015-04-02 04:45:34