How to use node-dir - 10 common examples

To help you get started, we’ve selected a few node-dir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 1j01 / retrores / extract-resources.js View on Github external
const extractResourcesToCorrespondingDirectoryStructure = (sourceRootPath, destinationRootPath)=> {
	console.log(`Extracting resources from: ${sourceRootPath}`);

	dir.subdirs(sourceRootPath, (err, sourceSubDirectoryPaths)=> {
		if (err) { throw err; }
		const sourceDirectoryPaths = [sourceRootPath].concat(sourceSubDirectoryPaths);

		mapLimit(sourceDirectoryPaths, 1,
			(sourceDirectoryPath, callback)=> {
				const sharedPath = path.relative(sourceRootPath, sourceDirectoryPath);
				const destinationDirectoryPath = path.join(destinationRootPath, sharedPath);
				mkdirp.sync(destinationDirectoryPath);
				resourcesExtract(sourceDirectoryPath, destinationDirectoryPath, (err)=> {
					if (err) { return callback(err); }
					fs.readdir(sourceDirectoryPath, (err, sourceFnames)=> {
						if (err) { return callback(err); }
						fs.readdir(destinationDirectoryPath, (err, destinationFnames)=> {
							if (err) { return callback(err); }
							// resultantResourceFnames = fnames;
							// may include directories; i'm assuming they won't match for now
github oracle / content-and-experience-toolkit / sites / bin / document.js View on Github external
resourceName = inputPath;
				inputPath = '';
			}
		}
		// console.log('argv.folder=' + argv.folder + ' inputPath=' + inputPath + ' resourceName=' + resourceName);
		var folderPath = !argv.folder || argv.folder === '/' || !inputPath ? [] : inputPath.split(path.sep);
		if (folderName) {
			folderPath.push(folderName);
		}
		console.log(' - target folder: ' + (resourceFolder ? (resourceLabel + ' > ' + resourceName) : 'Documents') + ' > ' + folderPath.join(' > '));

		var rootParentFolderLabel = resourceFolder ? resourceName : 'Home folder';

		// get all files to upload
		var folderContent = [];
		dir.paths(srcPath, function (err, paths) {
			if (err) {
				console.log(err);
				return reject();
			} else {
				// the top level folder
				if (folderName) {
					folderContent.push({
						fileFolder: '',
						files: []
					});
				}
				// get all sub folders including empty ones
				var subdirs = paths.dirs;
				for (var i = 0; i < subdirs.length; i++) {
					var subdir = subdirs[i];
					subdir = subdir.substring(srcPath.length + 1);
github mdn / bob / lib / utils.js View on Github external
function copyDirectory(sourceDir, destDir) {
    // gather all files in sourceDir
    dir.files(sourceDir, function(err, files) {
        if (err) {
            if (err.code === 'ENOENT' && err.path === sourceDir) {
                console.error(
                    'Specified directory "' +
                        sourceDir +
                        '" does not exist. \nPlease specify an existing directory relative to the root of the project.'
                );
                return;
            }

            console.error('Error reading file list', err);
            throw err;
        }

        // Do not copy .DS_Store files
        files.filter(function(file) {
github icfnext / iron / lib / operations / create-project.js View on Github external
clientLibs( function( libs ){

                if( libs.length !== 0 ){
                    var clientlibsPath      = libs[0].path.split( "/" );
                    config.clientlib_root   = clientlibsPath
                                                .splice( 0, clientlibsPath.indexOf('clientlibs') + 2 )
                                                .join('/');

                    fs.writeFileSync( '.ironrc' , JSON.stringify( config, null, 4 ));
                } else {
                    var nodeDir = require('node-dir');
                    nodeDir.subdirs(shell.pwd().stdout, function (err, subdirs) {
                        // Files is an array of filename

                        var index = subdirs.findIndex( function( filePath ){
                            var pathArray   = filePath.split('/');
                            var foundAt     = pathArray.indexOf("clientlibs");

                            return (foundAt !== -1);
                        } );


                        if( subdirs[index] === undefined ){

                            var etcIndex = subdirs.findIndex( function( filePath ){
                                var pathArray   = filePath.split('/');
                                var foundAt     = pathArray.indexOf("etc");
github icfnext / iron / dist / operations / create-project.js View on Github external
clientLibs(function (libs) {

                if (libs.length !== 0) {
                    var clientlibsPath = libs[0].path.split("/");
                    config.clientlib_root = clientlibsPath.splice(0, clientlibsPath.indexOf('clientlibs') + 2).join('/');

                    fs.writeFileSync('.ironrc', JSON.stringify(config, null, 4));
                } else {
                    var nodeDir = require('node-dir');
                    nodeDir.subdirs(shell.pwd().stdout, function (err, subdirs) {
                        // Files is an array of filename

                        var index = subdirs.findIndex(function (filePath) {
                            var pathArray = filePath.split('/');
                            var foundAt = pathArray.indexOf("clientlibs");

                            return foundAt !== -1;
                        });

                        if (subdirs[index] === undefined) {

                            var etcIndex = subdirs.findIndex(function (filePath) {
                                var pathArray = filePath.split('/');
                                var foundAt = pathArray.indexOf("etc");

                                return foundAt !== -1;
github Sotera / watchman / server / workers / tweet-processor.js View on Github external
return new Promise((res, rej) => {
    dir.readFilesStream(queuedFilesDir,
      { match: /\.json$/,
        recursive: false
      },
      (err, stream, next) => {
        if (err) return rej(err);
        console.log('found file to process: %s', stream.path);
        const lineReader = readline.createInterface({
          input: stream,
          terminal: false
        });

        lineReader
        .on('line', line => {
          let altered = alterTweet(line);
          if (altered) {
            // TODO: would be better to stream
github Sotera / watchman / server / workers / featurizer.js View on Github external
return new Promise((res, rej) => {
    dir.readFilesStream(queuedImagesDir,
      { match: /\.(jpg|jpeg|png)$/,
        recursive: false
      },
      (err, stream, next) => {
        if (err) return rej(err);
        let f = stream.path,
          renamed = f;
        console.log('found image to featurize: %s', f);
        // mark complete
        if (process.env.NODE_ENV === 'production') {
          renamed = path.join(processedImagesDir, path.basename(f));
          fs.renameSync(f, renamed);
        }
        triggerFeaturizer(renamed)
        .then(key => queue.add(key))
        .then(() => next())
github lazojs / lazo / lib / server / resolver / file.js View on Github external
fs.exists(directory, function (exists) {
                if (!exists) {
                    return callback(null, []);
                }

                dir.files(directory, function (err, files) {
                    if (err) { // TODO: error handling
                        throw err;
                    }

                    if (!options.basePath && !options.ext) {
                        return files;
                    }

                    for (var i = 0; i < files.length; i++) {
                        if (options.ext && path.extname(files[i]) !== options.ext) {
                            continue;
                        }
                        files[i] = options.basePath ? files[i].replace(options.basePath + '/', '') : files[i];
                        filtered.push(files[i]);
                    }
github Dudemullet / tenna / routes / videos.js View on Github external
var getMovies = function(cb) {
        var videoList = [];

        //Recursively get all files in dir
        dirExp.files(movieDir, function(err,files) {
            if(!files)
                return cb(videoList);

            // Get supported files with valid extensions (mp4, avi, etc...)
            var filteredVideos = files.filter(validExtensionsFilter);

            //Per video, construct a useful video object
            filteredVideos.forEach(function(val,i,arr){
                videoList.push(newVideo(val, movieDir));
            });

            cb(videoList);
        });
    }
github GladysAssistant / Gladys / api / services / MusicService.js View on Github external
var size;

		// check if the importation is finished
		/**
		 * Description
		 * @method checkIfDone
		 * @return 
		 */
		function checkIfDone(){
			inserted++;
			if(inserted >= size)
				callback(null);
		}

		// get recursively all the files in the folder
		dir.files(sails.config.music.folder, function(err, files) {
			if(err) return sails.log.warn(err);

			if(files){

				size = files.length;

			   	for(var i=0;i

node-dir

asynchronous file and directory operations for Node.js

MIT
Latest version published 8 years ago

Package Health Score

70 / 100
Full package analysis