S
S
smarisov6662022-03-19 19:41:21
JavaScript
smarisov666, 2022-03-19 19:41:21

How to solve the problem with the transfer of all elements?

function getFiles (dirPath, callback) {

    fs.readdir(dirPath, function (err, files) {
        if (err) return callback(err);

        var filePaths = [];
        async.eachSeries(files, function (fileName, eachCallback) {
            var filePath = path.join(dirPath, fileName);

            fs.stat(filePath, function (err, stat) {
                if (err) return eachCallback(err);

                if (stat.isDirectory()) {
                    getFiles(filePath, function (err, subDirFiles) {
                        if (err) return eachCallback(err);

                        filePaths = filePaths.concat(subDirFiles);
                        eachCallback(null);
                    });

                } else {
                    if (stat.isFile() && /YouTube_Accounts_\d+.txt$/.test(filePath)) {
                        filePaths.push(filePath);
                    }

                    eachCallback(null);
                }
            });
        }, function (err) {
            callback(err, filePaths);
        });

    });
}

function getDirectories(path) {
    return fs.readdirSync(path).filter(function (file) {
      return fs.statSync(path+'/'+file).isDirectory();
    });
}

fs.readFile("config.txt", "utf8", 
    function(error,data){
        if(error) throw error; 
        limit = data.match(/limit: (\d+)/)
        console.log('Set limit: ' + limit[1])
});


let dir_main; 

getFiles('./', function (err, files) {
    for (const item of getDirectories('./')) {
        if (item.startsWith('YT')) {
            dir_main = item
            for (const item of files) {
                const array = fs.readFileSync(item).toString().split("\n");
                for (const item of array) {
                    let check = item.match(/Account (.+) Subs: (\d+)/)
                    if (check != null || check != undefined) {
                        if (Number(check[2]) > Number(limit[1])) {
                            fska.move('./' + dir_main, './result/' + dir_main, err => {
                                if(err) return console.error(err);
                                console.log('success!');
                            });
                            fska.copy('./' + dir_main, './result/' + dir_main, err => {
                                if(err) return console.error(err);
                                console.log('success!');
                            });
                        }
                    }
                }
            }
        }
    }
});

I have this code, but the problem is that when the code gets to this point
for (const item of array) {
                    let check = item.match(/Account (.+) Subs: (\d+)/)
                    if (check != null || check != undefined) {
                        if (Number(check[2]) > Number(limit[1])) {
                            fska.copy('./' + dir_main, './result/' + dir_main, err => {
                                if(err) return console.error(err);
                                console.log('success!');
                            });
                        }
                     }

All directories that do not fit the check are transferred
if (Number(check[2]) > Number(limit[1])) {
                            fska.copy('./' + dir_main, './result/' + dir_main, err => {
                                if(err) return console.error(err);
                                console.log('success!');
                            });
                        }

maybe I'm doing something wrong or not right, maybe I need to use async?
I also noticed that due to the fact that I use for in for there is a big error, but I don’t really understand how to fix it?
7xOImuS.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question