Created
February 22, 2025 18:03
-
-
Save Tribhuwan-Joshi/d01ee239b4ec5204ea6c156e8cad5a34 to your computer and use it in GitHub Desktop.
Copy All folders with specific names that are present in n-level nested directories
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('node:fs/promises'); | |
const path = require('path'); | |
let c = 1; | |
async function fn(p, FolderName) { | |
const items = await fs.readdir(p, { withFileTypes: true }); | |
for (i of items) { | |
if (i.isDirectory()) { | |
if (i.name == FolderName) { | |
console.log(i); | |
await fs.cp(path.join(i.parentPath, i.name), `./all/finished-${c++}`, { | |
recursive: true, | |
}); | |
} | |
await fn(path.join(p, i.name)); | |
} | |
} | |
} | |
fn(path.join(__dirname, './'), 'finished'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment