【问题标题】:Is Extendscript able to duplicate a file using File Object ( File. )?Extendscript 是否能够使用文件对象( File. )复制文件?
【发布时间】:2019-07-12 01:49:24
【问题描述】:

想要在本地目录中复制具有新文件扩展名的文件。我没有看到任何使用文件对象复制文件的文档。

我看到File.copy() 等功能,但与复制或保存无关,没有带有新名称和扩展名的对话框。

var targetFile = new File('myFile');
targetFile.saveDlg('newFileName' + 'extension');

【问题讨论】:

  • 我不太明白这个问题。 File.copy() 在哪些方面不适合您?

标签: adobe extendscript


【解决方案1】:

要通过代码做到这一点,您必须更加明确。你可以试试这个:

function duplicateFile(path) {
  var content, extension, file, fileOk, name, newFile, newPath;
  file = new File(path);
  if(!file) {
    return
  }

  fileOk = file.open('r');

  if(fileOk){
    //Get file extension
    name = file.name.split('.');
    extension = name.pop();
    name.join('.');

    //Creating new file
    //Becareful with the name, you must to check that a file with the same name doesn't exists
    //if you don't want to overwrite it.
    name = name + '_copy.' + extension 
    newPath = file.parent.fsName + '/' + name
    newFile = new File(newPath);
    fileOk = newFile.open('w');

    //Writing content to new file
    if (fileOk) {
      newFile.write(content);
      newFile.close(); //Remember to close the files
    }
    file.close()
  }
}

【讨论】:

  • 谢谢米格尔 - 我会试试看
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-11
  • 1970-01-01
  • 2012-04-19
  • 2010-12-18
  • 2012-09-02
  • 1970-01-01
相关资源
最近更新 更多