shelljs / shx

Portable Shell Commands for Node
MIT License
1.72k stars 44 forks source link

cp command with --parents? #175

Closed basickarl closed 4 years ago

basickarl commented 4 years ago

I'm trying to do the following: cp **/*.csv --parents ../target

Keep the hierarchy in other words, is this possible in shx as of now?

nfischer commented 4 years ago

We don't support that option. It appears to be non-POSIX, so it's not high priority.

I think you could write a script with ShellJS to achieve the same effect. I didn't test this, but something like this might work:

var destinationDir = '../target'; // or whatever your destination is
shell.ls('**/*.csv').forEach(csvFile => {
  // csvFile should be of the form "subdir/othersubdir/file.csv", where "subdir"
  // is a subdir of the current working directory
  var outputDir = path.join(destinationDir, path.dirname(csvFile));
  shell.mkdir('-p', outputDir);
  shell.cp(csvFile, outputDir);
});

Let me know if that works for you (or if you need to make edits).

basickarl commented 4 years ago

Thanks for the quick response! Went with https://www.npmjs.com/package/copyfiles got the job done.