<commit_before>var Q = require('q');
var fs = require('fs');

var workspace = require('../workspace');

var list = function(args) {
    return workspace.path(args.path || ".")
    .then(function(_path) {
        console.log(_path);
    });
};

module.exports = {
    'list': list
};<commit_msg>Add method list to fs service<commit_after>var Q = require('q');
var _ = require('lodash');
var fs = require('fs');
var path = require('path');

var workspace = require('../workspace');


// List files in a directory
var list = function(args) {
    return workspace.path(args.path || ".")
    .then(function(_path) {
        return [Q.nfcall(fs.readdir, _path), _path];
    })
    .spread(function(paths, root) {
        return _.reduce(paths, function(prev, _path) {
            return prev.then(function(files) {
                var _folder = path.resolve(root, _path);

                return Q.nfcall(fs.stat, _folder)
                .then(function(stat) {
                    files.push({
                        'name': _path,
                        'directory': stat.isDirectory(),
                        'size': stat.size,
                        'mtime': stat.mtime.getTime(),
                        'atime': stat.atime.getTime()
                    });

                    return files;
                })
            })

        }, Q([]))
    });
};

module.exports = {
    'list': list
};
{'fraction_non_alphanumeric': 0.15868477483917084, 'fraction_numerical': 0.0, 'mean_word_length': 1.7450980392156863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2926099', 'n_tokens_mistral': 414, 'n_tokens_neox': 394, 'n_words': 86}