Last active
November 29, 2023 16:23
-
-
Save ericcarraway/eeaf25ac60cfeb871d505ab28f1f2572 to your computer and use it in GitHub Desktop.
Node.js script to find fcpbundle 'Render Files' folders for deletion
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
// 1. node fcpbundle-cleaner.js > fcpbundle-cleaner.sh | |
// 2. Inspect the resulting `fcpbundle-cleaner.sh` file. | |
// 3. Run the `fcpbundle-cleaner.sh` file. | |
const { execSync } = require(`node:child_process`); | |
/** | |
* Utility to take the output of an `execSync` 'find' command | |
* and return an array of strings. | |
*/ | |
const outputToArr = (output) => output.toString().split(`\n`).filter(Boolean); | |
/** Returns the relative paths of `.fcpbundle` in the given directory. */ | |
const findFcpBundles = () => { | |
const findOutput = execSync(`find . -name '*.fcpbundle'`); | |
return outputToArr(findOutput); | |
}; | |
/** | |
* For a given `fcpbundle` path, | |
* return the 'Render Files folders within. | |
*/ | |
const findRenderFilesFolders = (fcpbundle) => { | |
const findOutput = execSync(`find '${fcpbundle}' -name 'Render Files'`); | |
return outputToArr(findOutput); | |
}; | |
/** | |
* For a given 'Render Files' folder, | |
* return the 'High Quality Media' folders within. | |
*/ | |
const findHighQualityMediaFolder = (renderFilesFolder) => { | |
const findOutput = execSync( | |
`find '${renderFilesFolder}' -name 'High Quality Media'`, | |
); | |
return outputToArr(findOutput); | |
}; | |
/** | |
* For a given 'Render Files' folder, | |
* return the 'Peaks Data' folders within. | |
*/ | |
const findPeaksDataFolder = (renderFilesFolder) => { | |
const findOutput = execSync(`find '${renderFilesFolder}' -name 'Peaks Data'`); | |
return outputToArr(findOutput); | |
}; | |
/** | |
* For a given 'Render Files' folder, | |
* return the 'Thumbnail Media' folder within. | |
*/ | |
const findThumbnailMediaFolder = (renderFilesFolder) => { | |
const findOutput = execSync( | |
`find '${renderFilesFolder}' -name 'Thumbnail Media'`, | |
); | |
return outputToArr(findOutput); | |
}; | |
const paths = []; | |
findFcpBundles().forEach((fcpbundle) => { | |
findRenderFilesFolders(fcpbundle).forEach((renderFilesFolders) => { | |
// 'Render Files/High Quality Media' | |
findHighQualityMediaFolder(renderFilesFolders).forEach( | |
(highQualityMediaFolder) => { | |
paths.push(highQualityMediaFolder); | |
}, | |
); | |
// 'Render Files/Peaks Data' | |
findPeaksDataFolder(renderFilesFolders).forEach( | |
(highQualityMediaFolder) => { | |
paths.push(highQualityMediaFolder); | |
}, | |
); | |
// 'Render Files/Thumbnail Media' | |
findThumbnailMediaFolder(renderFilesFolders).forEach( | |
(highQualityMediaFolder) => { | |
paths.push(highQualityMediaFolder); | |
}, | |
); | |
}); | |
}); | |
const output = paths.map((path) => `trash '${path}'`).join(`\n`); | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment