const path = require('path')
const fs = require('fs')
const { throws } = require('assert')
const { error, info } = require('console')
const sourceDir = process.argv[2]
const targetDir = process.argv[3]
const copy = (sd, td) => {
const sourceFile = fs.readdirSync(sd, { withFileTypes: true })
for (const file of sourceFile) {
const srcFile = path.resolve(sd, file.name)
const tagFile = path.resolve(td, file.name)
if (file.isDirectory() && !fs.existsSync(tagFile)) {
fs.mkdirSync(tagFile, err => console.log(err))
copy(srcFile, tagFile)
} else if (file.isDirectory() && fs.existsSync(tagFile)) {
copy(srcFile, tagFile)
}
!file.isDirectory() && fs.copyFileSync(srcFile, tagFile, fs.constants.COPYFILE_FICLONE)
}
}
const run = async () => {
const startTime = await new Date().getTime()
console.log(!fs.existsSync(sourceDir),)
if (!fs.existsSync(sourceDir)) {
throw error('no such file or directory')
} else if (!fs.existsSync(targetDir)) {
await fs.mkdirSync(targetDir, err => console.log(err))
await copy(sourceDir, targetDir)
} else {
await copy(sourceDir, targetDir)
}
const endTime = await new Date().getTime()
console.log("耗时:", ((endTime - startTime) / 1000).toFixed(2) + "s");
}
run()