Using rm with extended globbing in node js
I need to do daily cleanup of a folder for my app, so I ve made a bash
script (with some help of superuser) to do so.
It work well from the console, but it is not interpreted correctly from node.
Here the working script:
rm ./app/download/!("test1"|"test4");
Which I ve thought would work like this in node.js:
var spawn = require('child_process').spawn,
PATH = process.argv[1].substr(0, process.argv[1].lastIndexOf('/') +
1), //Get the full path to the directory of the app
arg = [PATH + 'download/!(\"', 'test1', '\"|\"', 'test4', ('\")'],
child = spawn ('rm', arg);
child.stderr.on('data', function(data) {
console.log('stderr:' + data);
});
But I get rm interpret them by being different files:
stderr:rm: cannot remove '/home/user/app/download("' : No such file or
directory
rm cannot remove 'test1' : No such file or directory
...
So I ve tried by changing arg to this:
arg = [PATH + 'download/!("' + 'test1' + '"|"' + 'test4' + '")']
But I get
stderr:rm: cannot remove '/home/user/app/download/!("test1"|"test2")' :
No such file or directory
I m trying with exec, but I don t think this is the problem since it seems
the spawned rm don t interpret the extended glob thing, which is active by
default...
No comments:
Post a Comment