MCPcopy Create free account
hub / github.com/BabylonJS/BabylonReactNative / deleteFolderRecursive

Function deleteFolderRecursive

Package/gulpfile.js:283–310  ·  view source on GitHub ↗
(folderPath, excludeSubFolders = [])

Source from the content-addressed store, hash-verified

281}
282
283function deleteFolderRecursive(folderPath, excludeSubFolders = []) {
284 if (!fs.existsSync(folderPath)) return;
285
286 const entries = fs.readdirSync(folderPath, { withFileTypes: true });
287
288 for (const entry of entries) {
289 const fullPath = path.join(folderPath, entry.name);
290
291 if (entry.isDirectory()) {
292 if (excludeSubFolders.includes(entry.name)) {
293 continue; // Skip this folder
294 }
295 deleteFolderRecursive(fullPath, excludeSubFolders);
296 } else {
297 fs.unlinkSync(fullPath);
298 }
299 }
300
301 // After deleting contents, delete the root folder if it's not in the excluded list
302 const folderName = path.basename(folderPath);
303 if (!excludeSubFolders.includes(folderName)) {
304 const remaining = fs.readdirSync(folderPath);
305 if (remaining.length === 0) {
306 fs.rmdirSync(folderPath);
307 console.log(`Deleted folder: ${folderPath}`);
308 }
309 }
310}
311
312function copyRecursiveExcludingGit(src, dest) {
313 if (!fs.existsSync(src)) return;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected