Как сделать скриншот содержимого подпапок, используя узел js или javascript - PullRequest
0 голосов
/ 17 апреля 2019

У меня есть папка и внутри нее у меня есть подпапки (или каталоги). Теперь эти каталоги содержат некоторые файлы или контент. Что я хочу, так это то, что я хочу сделать снимок экрана со всем содержимым подпапок, используя node.js или файловую систему JavaScript api, программно и периодически для всех подпапок. Так как же мне этого добиться?

Ниже приведен код, который я пробовал, но не могу достичь желаемого результата. Я получаю только скриншот текущего экрана рабочего стола, который активен (над которым я сейчас работаю), и он не нужен. Поэтому потребуйте ваши предложения или решение для этого. Заранее спасибо за помощь.

//specify the interval time in seconds 
var interval = 1;

//specify the path to which screenshots are to be stored
var imgPath = 'screenshots';

//specify any prefix for the image if needed, preferably with a trailing underscore.Else leave it blank
var imgPrefix = '';

//specify interval in seconds to clear the screenshots folder.Leave it blank if no need for reset
var clearInterval = '';

var fs  = require('fs');

var screenshot = require('desktop-screenshot');

const scriptsPath = './folders';
const process = require('process');
const path = require('path');

// Returns Top Level Folders List within a given folder
function getFolders(dir) {
  return fs.readdirSync(dir)
    .filter(function(file) {
      return fs.statSync(path.join(dir, file)).isDirectory();
    });
}

function getFolderListWithScreenshot() {

  var count = 0;

  // Get folders list with names
  var folders = getFolders(scriptsPath);
  if (folders.length === 0) return done(); // nothing to do!

  return folders.map(function(folder) {


    const directoryPath = path.join(__dirname + "/" + scriptsPath , folder, './');

    const realFolderPath = path.dirname(directoryPath).split(path.sep).pop();

    console.log(directoryPath);

    console.log(realFolderPath);

    process.chdir(directoryPath);

    // Printing Current Working Directory
    console.log('Current Working directory: ' + process.cwd());

    console.log(process.cwd()+": done");

    count++;

    screenshot(realFolderPath+" ("+count+").jpg", {width: 1440, height: 900, quality: 60}, function(error, complete) {
        if(error) {
            console.log("Screenshot failed", error);
        }
        else {
            console.log("Screenshot succeeded");
        }
    });

  });
}

getFolderListWithScreenshot();
...