Skip to content

Instantly share code, notes, and snippets.

@Tribhuwan-Joshi
Created February 22, 2025 18:03
Show Gist options
  • Save Tribhuwan-Joshi/d01ee239b4ec5204ea6c156e8cad5a34 to your computer and use it in GitHub Desktop.
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
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