const fs = require('fs'); const path = require('path'); var execSync = require('child_process').execSync; const getAllFiles = function (dirPath, arrayOfFiles) { files = fs.readdirSync(dirPath); arrayOfFiles = arrayOfFiles || []; files.forEach(function (file) { if (fs.statSync(dirPath + '/' + file).isDirectory()) { arrayOfFiles = getAllFiles(dirPath + '/' + file, arrayOfFiles); } else if (file.endsWith('.md')) { arrayOfFiles.push(path.join(dirPath, '/', file)); } }); return arrayOfFiles; }; for (const file of getAllFiles('C:\\temp\\src')) { console.log(file); fs.mkdirSync(path.dirname(file.replace('C:\\temp\\src', 'C:\\temp\\dist')), { recursive: true }); const srcPath = file.replace('C:\\temp\\src', './src').split(path.sep).join(path.posix.sep); const distPAth = file .replace('C:\\temp\\src', './dist') .replace('.md', '.odt') .split(path.sep) .join(path.posix.sep); execSync(`docker run --rm -v C:/temp:/data pandoc/core "${srcPath}" -f markdown -t odt -o "${distPAth}"`, { stdio: 'inherit', }); }