E
E
Evgen2015-11-13 20:33:19
JavaScript
Evgen, 2015-11-13 20:33:19

Node.js - child_process - How to specify not a specific file, but the file type *.doc && *.docx?

Good people, help is needed!

var exec = require('child_process').exec;
exec('AbiWord.exe —to=html testdoc.docx');

Everything is fine here, everything works! but how to make it translate into html not specifically this file, but let's say all files of the .docx and (or) .doc type in a specific folder. Thank you! (PS *.docx doesn't work)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Kolchenko, 2015-11-13
@unikz

Scan a directory with files and run AbiWord in a loop, substituting file paths

D
Duha666, 2015-11-13
@Duha666

As far as I understand, AbiWord only accepts one file per conversion. So it just needs to get *.doc(x) with a glob or whatever. Then call AbiWord via exec from each found file

E
Evgen, 2015-11-15
@Dekol

It came out something like:

var exec = require('child_process').execFileSync; 
var abi = 'brain/AbiWord/bin/AbiWord.exe';
var fs = require('fs');
var dir2read = ('test');
fs.readdir(dir2read, function(err,files){
    if(err) throw err;
    files.forEach(function(file){
if (!err) 
exec(abi, [file, '--to=html']);
});
});

But in this case, he (abiword'u?) needs duplicate files in the root directory, otherwise he doesn't like the file name.... some kind of nonsense...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question