国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

Nodejs實(shí)現(xiàn)多文件夾文件同步

2019-11-19 12:41:17
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例為大家分享了Nodejs實(shí)現(xiàn)多文件夾文件同步的具體代碼,供大家參考,具體內(nèi)容如下

package.json{ "name": "asyncFile", "version": "0.0.1", "dependencies":{ "fs-sync":"", "later":"" }}

asycnFile.js

var fsSync = require('fs-sync');var fs = require('fs');var util = require("util");var later = require("later");//需要同步的文件夾路徑var path = { "pathOne": "/home/lincoln/testAsync/dirOne/", "pathTwo": "/home/lincoln/testAsync/dirTwo/"};//需要同步的文件夾名稱var asyncDir = ["img", "music"];var dirFilesOne;var dirFilesTwo;//讀取文件夾信息function readDir(dirName){ dirFilesOne = fs.readdirSync(path.pathOne + dirName); dirFilesTwo = fs.readdirSync(path.pathTwo + dirName);}//使用fs-sync模塊拷貝文件信息function useFileCopy(sourcePath,distPath,copyFiles) { for(var index in copyFiles){  fsSync.copy(sourcePath+copyFiles[index],distPath+copyFiles[index]) }}//統(tǒng)計(jì)需要同步的文件信息function needCopyFiles(sourceFiles, distFiles) { var needCopyFiles = []; for (var index in sourceFiles) {  if (distFiles.indexOf(sourceFiles[index]) == -1) {   needCopyFiles.push(sourceFiles[index]);   console.log("needAsyncFile-->"+sourceFiles[index]);  } } return needCopyFiles;}//同步文件function copyFile(dirName) { var sourcePath = path.pathOne + dirName +"/"; var distPath = path.pathTwo + dirName +"/"; readDir(dirName) useFileCopy(sourcePath,distPath,needCopyFiles(dirFilesOne,dirFilesTwo)); readDir(dirName); useFileCopy(distPath,sourcePath,needCopyFiles(dirFilesTwo,dirFilesOne));}//for (var index in asyncDir) {// //console.log(asyncDir[index])// console.log(new Date() +" 執(zhí)行同步--->"+asyncDir[index])// copyFile(asyncDir[index]);//}var sched = later.parse.recur().every(10).second(), t = later.setInterval(function() {  for (var index in asyncDir) {   //console.log(asyncDir[index])   console.log(new Date() +" 執(zhí)行同步--->"+asyncDir[index]);   copyFile(asyncDir[index]);  } }, sched);

代碼只是能用,菜鳥寫法,等js這塊有深入理解了之后,再修改這塊的代碼,也希望js大牛指點(diǎn)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大洼县| 黔西县| 封丘县| 永康市| 梁平县| 綦江县| 建昌县| 安泽县| 九江县| 忻城县| 上饶县| 新泰市| 进贤县| 天祝| 贵定县| 普定县| 翁源县| 大名县| 五指山市| 永春县| 建水县| 潞城市| 雅江县| 阜城县| 昭通市| 米易县| 阿城市| 赞皇县| 焉耆| 凤阳县| 农安县| 鄱阳县| 教育| 通海县| 晋城| 金湖县| 金山区| 佳木斯市| 贺州市| 宜良县| 集贤县|