swEnv.js 583 B

1234567891011121314151617181920
  1. const fs = require("fs");
  2. const path = require("path");
  3. const [sourceFile, targetFile] = process.argv.slice(2);
  4. if (!sourceFile || !targetFile) {
  5. console.error("请提供源文件和目标文件的路径作为参数。");
  6. process.exit(1);
  7. }
  8. const sourcePath = path.resolve(sourceFile);
  9. const targetPath = path.resolve(targetFile);
  10. // 复制文件
  11. fs.copyFile(sourcePath, targetPath, (err) => {
  12. if (err) {
  13. console.error("复制文件时出错:", err);
  14. process.exit(1);
  15. }
  16. console.log(`成功复制文件从 ${sourcePath} 到 ${targetPath}`);
  17. });