Last active
August 3, 2021 02:04
-
-
Save myesn/d6cab2a374b2cbbb2cdedd0fa85d311e to your computer and use it in GitHub Desktop.
比较两个文件夹中的文件, 以 origin 为基础, target 文件夹中缺失了哪些文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const origin = 'C:/origin'; | |
const target = 'C:/target'; | |
const originFiles = fs.readdirSync(origin); | |
const targetFiles = fs.readdirSync(target); | |
originFiles.forEach((el) => { | |
const full = path.join(origin, el); | |
if (fs.lstatSync(full).isFile()) { | |
if ( | |
!targetFiles.some( | |
(x) => filenameWithoutExtension(x) === filenameWithoutExtension(el) | |
) | |
) { | |
console.log(el); | |
} | |
} | |
}); | |
function filenameWithoutExtension(filename) { | |
return filename.split('.').slice(0, -1).join('.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment