Step #3 in "readdir" Operation
499710
function readAndSaveFileListing(bundle) {
		debugLS('in readAndSaveFileListing');
		var defered = q.defer();
		self.readArray('FILE_IO_NAME_READ', bundle.FILE_IO_NAME_READ_LEN.val)
		.then(function(fileNameChars) {
			debugLS('in readAndSaveFileListing raw', fileNameChars);
			var fileName = '';
			fileNameChars.forEach(function(fileNameChar) {
				if(fileNameChar !== 0) {
					fileName += String.fromCharCode(fileNameChar);
				}
			});
			// Save the file name.
			if(!bundle.noFilesOnCard) {
				bundle.fileNames.push(fileName);
			}
			debugLS('Debug CWD:', bundle.cwd, fileName);
			var filePath = path.posix.join(bundle.cwd, fileName);
			var pathInfo = path.posix.parse(filePath);
			var fileInfo = {
				'name': fileName,
				'ext': pathInfo.ext,
				'path': filePath,
				'pathInfo': pathInfo,
				'isDirectory': bundle.FILE_IO_ATTRIBUTES.isDirectory,
				'isFile': bundle.FILE_IO_ATTRIBUTES.isFile,
				'size': bundle.FILE_IO_SIZE.val,
				'sizeStr': bundle.FILE_IO_SIZE.str,
			};
			// Save the file's info.
			if(!bundle.noFilesOnCard) {
				bundle.files.push(fileInfo);
			}
			
			debugLS('in readAndSaveFileListing fileInfo', fileInfo);
			defered.resolve(bundle);
		}, function(err) {
			debugLS('in readAndSaveFileListing err', err);
			bundle.isError = true;
			bundle.errorStep = 'readAndSaveFileListing';
			bundle.error = modbusMap.getErrorInfo(err);
			bundle.errorCode = err;
			defered.reject(bundle);
		});
		return defered.promise;
	}
319960
function processDirectory(directory: string) {
      // If we were rejected then we should not continue.
      if (rejected === true) {
        return;
      }
      // We are now waiting on this asynchronous task.
      waiting++;
      // Read the directory...
      fs.readdir(directory, (error, fileNames) => {
        if (error) {
          return reject(error);
        }
        // Process every file name that we got from reading the directory.
        for (let i = 0; i < fileNames.length; i++) {
          processFilePath(directory, fileNames[i]);
        }
        // We are done with this async task.
        done();
      });
    }
343321
function _emptyDirectoryProm (directory) {

			return new Promise((resolve, reject) => {

				readdir(directory, (err, files) => {
					return err ? reject(err) : resolve(files);
				});

			}).then((files) => {

				const result = [];

					for (let i = 0; i < files.length; ++i) {
						result.push(join(directory, files[i]));
					}

				return Promise.resolve(result);

			}).then((files) => {
				return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
			});

		}
968324
function (dir) {
    let files = [];
    let list = fs.readdirSync(dir);
    list.forEach(function (file) {
        file = dir + '/' + file;
        let stat = fs.statSync(file);
        if (stat && stat.isDirectory()) files = files.concat(walk(file));
        else files.push(file);
    });
    return files;
}
664000
function step3 ( folder ) {
				var is, nodes = folder.nodes, alpha = function ( n1, n2 ) {
					return n1.name < n2.name ? -1 : n1.name > n2.name ? 1 : 0;
				};
				folder.nodes = nodes.filter ( function ( node ) {
					return (( is = node.nodes )) ? step3 ( node ) : false;
				}).sort ( alpha ).concat ( nodes.filter ( function ( node ) {
					return !node.nodes;
				}).sort ( alpha ));
				return folder;
			}
286812
function _dir_readdir()
    {
        if (isset($this->entries[$this->pos])) {
            return $this->entries[$this->pos++];
        }
        return false;
    }
1096499
def complete_from_dir(directory):
    '''
    
    '''
    global currDirModule
    if currDirModule is not None:
        if len(sys.path) > 0 and sys.path[0] == currDirModule:
            del sys.path[0]

    currDirModule = directory
    sys.path.insert(0, directory)
785142
def _enter_single_subdir(root_dir):
    """"""
    current_cwd = os.getcwd()
    try:
        dest_dir = root_dir
        dir_list = os.listdir(root_dir)
        if len(dir_list) == 1:
            first = os.path.join(root_dir, dir_list[0])
            if os.path.isdir(first):
                dest_dir = first
        else:
            dest_dir = root_dir
        os.chdir(dest_dir)
        yield dest_dir
    finally:
        os.chdir(current_cwd)
1056653
function getFilesInDirectory(entry, reader, accumEntries, existingPromise) {
        var promise = existingPromise || new qq.Promise(),
            dirReader = reader || entry.createReader();

        dirReader.readEntries(
            function readSuccess(entries) {
                var newEntries = accumEntries ? accumEntries.concat(entries) : entries;

                if (entries.length) {
                    setTimeout(function() { // prevent stack overflow, however unlikely
                        getFilesInDirectory(entry, dirReader, newEntries, promise);
                    }, 0);
                }
                else {
                    promise.success(newEntries);
                }
            },

            promise.failure
        );

        return promise;
    }
806146
function(sourceDir, newDirLocation, opts) {

        if (!opts || !opts.preserve) {
            try {
                if(fs.statSync(newDirLocation).isDirectory()) {
                    exports.rmdirSyncRecursive(newDirLocation);
                }
            }
            catch(e) { }
        }

        /*  Create the directory where all our junk is moving to; read the mode of the source directory and mirror it */
        var checkDir = fs.statSync(sourceDir);
        try {
            fs.mkdirSync(newDirLocation, checkDir.mode);
        }
        catch (e) {
            //if the directory already exists, that's okay
            if (e.code !== 'EEXIST') {
                throw e;
            }
        }

        var files = fs.readdirSync(sourceDir);

        for(var i = 0; i < files.length; i++) {
            var currFile = fs.lstatSync(sourceDir + "/" + files[i]);

            if(currFile.isDirectory()) {
                /*  recursion this thing right on back. */
                copyDirectoryRecursiveSync(sourceDir + "/" + files[i], newDirLocation + "/" + files[i], opts);
            }
            else if(currFile.isSymbolicLink()) {
                var symlinkFull = fs.readlinkSync(sourceDir + "/" + files[i]);
                fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]);
            }
            else {
                /*  At this point, we've hit a file actually worth copying... so copy it on over. */
                var contents = fs.readFileSync(sourceDir + "/" + files[i]);
                fs.writeFileSync(newDirLocation + "/" + files[i], contents);
            }
        }
    }
472215
function step5 ( folder ) {
				folder.filenames = folder.filenames || folder.nodes.map ( function ( node ) {
					return node.nodes ? step5 ( node ).filenames : node.name.toLowerCase ();
				}).join ( " " );
				return folder;
			}
739618
def read_folder(directory):
    
    res = []
    for filename in os.listdir(directory):
        with io.open(os.path.join(directory, filename), encoding="utf-8") as f:
            content = f.read()
            res.append(content)
    return res
1086269
async function scandir(dir, recursive=true, absolutePaths=false){
    // get absolute path
    const absPath = _path.resolve(dir);

    // stats command executable ? dir/file exists
    const stats = await _fs.stat(absPath);

    // check if its a directory
    if (!stats.isDirectory()){
        throw new Error('Requested directory <' + absPath  + '> is not of type directory');
    }

    // use absolute paths ?
    if (absolutePaths){
        dir = absPath;
    }

    // stack of directories to scan
    const dirstack = [dir];

    // list of files
    const files = [];

    // list of directories
    const directories = [];

    // iterative scan files
    while (dirstack.length > 0){
        // get current directory
        const currentDir = dirstack.pop();

        // get current dir items
        const itemNames = await _fs.readdir(currentDir);

        // get item stats (parallel)
        const itemStats = await Promise.all(itemNames.map((item) => _fs.stat(_path.join(currentDir, item))));

        // process item stats
        for (let i=0;i<itemNames.length;i++){
            // prepend current path
            const currentItem = _path.join(currentDir, itemNames[i]);

            // directory ? push to stack and directory list
            if (itemStats[i].isDirectory()){
                // recursive mode ?
                if (recursive){
                    dirstack.push(currentItem);
                }
                
                // store dir entry
                directories.push(currentItem);

            // file, socket, symlink, device..
            }else{
                // push to filelist
                files.push(currentItem);
            }
        }
    }

    // return file and directory list
    return [files, directories];
}
664291
function step4 ( folder ) {
				while ( folder.nodes.length === 1 && folder.nodes [ 0 ].nodes ) {
					//folder.hidden = true;
					folder = folder.nodes [ 0 ];
				}
				return folder;
			}
650638
public function dir_readdir()
    {
        $dir = $this->dirIterator->current();
        if (null === $dir) {
            return false;
        }

        $this->dirIterator->next();
        return $dir->getName();
    }
829106
function mkdirIf(dir, parent) {
	var path = parent ? parent : ".";
	if (getDirectories(path).indexOf(dir) == -1) fs.mkdirSync(path + "/" + dir);
}
587213
function crawlDirectoryWithFS(parent, sync) {
    return fsCmd('readdir', sync, parent).then(function (things) {
        return Q.all(things.map(function (file) {
            file = path.join(parent, file);
            return Q.all([file, fsCmd('stat', sync, file)]);
        }));
    }).then(function (stats) {
        return Q.all(stats.map(function (args) {
            var file = args[0], stat = args[1];
            if (stat.isDirectory()) {
                return crawlDirectoryWithFS(file, sync);
            }
            return file;
        }));
    }).then(function (grouped) {
        return [].concat.apply([], grouped);
    });
}