fs.readdirSync(inputFolder).forEach(function (dirContent) { dirContent = path.resolve(inputFolder, dirContent); if (getSubFolders && fs.statSync(dirContent).isDirectory()) { results = results.concat(helpers.findLUFiles(dirContent, getSubFolders, extType)); } if (fs.statSync(dirContent).isFile()) { if (dirContent.endsWith(extType)) { results.push(dirContent); } } });
function readUploadFiles(dir) { const rootPath = path.join(__dirname, dir); const dirs = fs.readdirSync(rootPath); return dirs.reduce((all, file) => { const curPath = path.join(rootPath, file); const isDir = fs.statSync(curPath).isDirectory(); const extname = path.extname(curPath); if(!isDir && extname !== '.map') { all.push(curPath); } return all; }, []); }
function recursivelyDelete(filePath) { //check if directory or file let stats = fs.statSync(filePath); //if file unlinkSync if (stats.isFile()) { fs.unlinkSync(filePath); } //if directory, readdir and call recursivelyDelete for each file else { let files = fs.readdirSync(filePath); files.forEach((file) => { recursivelyDelete(path.join(filePath, file)); }); fs.rmdirSync(filePath); } }
function rmdir(dir) { if (!fs.existsSync(dir)) { return null; } fs.readdirSync(dir).forEach(f => { let pathname = path.join(dir, f); if (!fs.existsSync(pathname)) { return fs.unlinkSync(pathname); } if (fs.statSync(pathname).isDirectory()) { return rmdir(pathname); } else { return fs.unlinkSync(pathname); } }); return fs.rmdirSync(dir); }
const watchFileCreated = (filename) => new Promise((resolve, reject) => { const TIMEOUT = 800 const INTERVAL = 100 const threshold = TIMEOUT / INTERVAL let counter = 0 const interval = setInterval(() => { // On some CI runs file is created but not filled if (existsSync(filename) && statSync(filename).size !== 0) { clearInterval(interval) resolve() } else if (counter <= threshold) { counter++ } else { clearInterval(interval) reject(new Error(`${filename} was not created.`)) } }, INTERVAL) })
broker.createService({ name: "file", actions: { get(ctx) { const fileName = "d:/src.zip"; const stat = fs.statSync(fileName); let uploadedSize = 0; const stream = fs.createReadStream(fileName); stream.on("data", chunk => { uploadedSize += chunk.length; this.logger.info("SEND: ", Number(uploadedSize / stat.size * 100).toFixed(0) + `% (${chunk.length})`); }); stream.on("close", () => { getSHA(fileName).then(hash => { broker.logger.info("File sent."); broker.logger.info("SHA:", hash); broker.logger.info("Size:", stat.size); }); }); return stream; } } });
function readFiles(basepath, pathname, files, condenseDots) { basepath = basepath || '.'; pathname = pathname || '.'; condenseDots = !!condenseDots; return fs.readdirSync(path.join(basepath, pathname)).reduce((files, filename) => { let savename = (condenseDots && filename.substr(0, 2) === '..') ? filename.substr(1) : filename; let savepath = path.join(pathname, savename).split(path.sep).join('/'); let filepath = path.join(pathname, filename); let fullpath = path.join(basepath, filepath); if (fs.statSync(fullpath).isDirectory()) { return readFiles(basepath, filepath, files, condenseDots); } else { files[savepath] = fs.readFileSync(fullpath); return files; } }, files || {}); }
function getEntries(entryPath, entryObj) { const files = fs.readdirSync(entryPath); files.forEach(function(filePath) { const fullpath = `${entryPath}/${filePath}`; const info = fs.statSync(fullpath); if (info.isDirectory()) { getEntries(fullpath, entryObj); } else { if (fullpath && fullpath.indexOf('.DS_Store') >= 0) { return; } let key = fullpath.replace('./js/', ''); key = key.replace('.js', ''); entryObj[key] = fullpath; } }); return entryObj; }
async function parseFileFromArg(arg, infoMode) { if (arg.indexOf('file:') === 0) { let filename = arg.slice('file:'.length); let file; try { file = fs.readFileSync(filename); file = JSON.stringify({_base64: file.toString('base64')}); } catch (e) { return new Error(`Can not read file: "${filename}"`); } return file; } else if (arg.indexOf('pack:') === 0) { let filename = arg.slice('pack:'.length); let dir; try { dir = fs.statSync(filename); } catch (e) { throw new Error(`Can not pack "${filename}", directory not found.`); } if (!dir.isDirectory()) { throw new Error(`Can not pack "${filename}", is not a directory.`); } let tarball = await Tar.pack(filename, infoMode); let file = JSON.stringify({_base64: tarball.toString('base64')}); return file; } return arg; }
function uploadPromise(url) { const name = path.basename(url); const type = mime.getType(name); const stream = fs.createReadStream(url); const {size} = fs.statSync(url); return new Promise((resolve, reject) => { cos.putObject({ Bucket: 'webchat-1251965041', Region: 'ap-beijing', Key: name, ContentType: type, Body: stream, ContentLength: size // FilePath: url }, function (err, data) { if(err) { reject(err); return; } if(data.statusCode === 200) { resolve('success'); } console.log(data); }); }) }
/* * Helper to get an executable */ const getDockerBin = (bin, base) => { // Do platform appropriate things to get started const join = (process.platform === 'win32') ? path.win32.join : path.posix.join; let binPath = (process.platform === 'win32') ? join(base, `${bin}.exe`) : join(base, bin); // Use PATH compose executable on posix if ours does not exist if (process.platform !== 'win32' && (!fs.existsSync(binPath) || fs.statSync(binPath).isDirectory())) { binPath = _.toString(shell.which(bin)); } // If the binpath still does not exist then we should set to false and handle downstream if (!fs.existsSync(binPath)) return false; // Otherwise return a normalized binpath switch (process.platform) { case 'darwin': return path.posix.normalize(binPath); case 'linux': return path.posix.normalize(binPath); case 'win32': return path.win32.normalize(binPath); } }
const stat = fs.statSync(fileName); let uploadedSize = 0;
const joinedPath = path.join(sourcePath, item); if (fs.existsSync(joinedPath)) { if (fs.statSync(joinedPath).isDirectory()) { directories.push(item); } else {
var removeFolder=function (path) { var files = []; if(fs.existsSync(path)) { files = fs.readdirSync(path); files.forEach(function(file, index) { var curPath = path + "/" + file; if(fs.statSync(curPath).isDirectory()) { removeFolder(curPath); } else { fs.unlinkSync(curPath); } }); fs.rmdirSync(path); } }
function getEntries(entryPath, entryObj) { const files = fs.readdirSync(entryPath); files.forEach(function(filePath) { const fullpath = `${entryPath}/${filePath}`; const info = fs.statSync(fullpath); if (info.isDirectory()) { getEntries(fullpath, entryObj); } else { if (fullpath && fullpath.indexOf('.DS_Store') >= 0) { return; } let key = fullpath.replace('./js/', ''); key = key.replace('.js', ''); entryObj[key] = fullpath; } }); return entryObj; }