2017-06-02 89 views
0

檢查以查看txt文件是否已存在。如果存在,我想打開並追加。如果!存在,我想創建,打開,寫入。我不知道如何將文件添加...JavaScript:從After Effects中寫入和附加文本文件

這裏是到目前爲止我的代碼:

function writeReport(path, reportText) { 

    var reportFile = new File(path + "/font_report.txt"); 

    if(reportFile.exists){ 
     alert('file already exists'); 

     reportFile.open("w"); 
     reportFile.write(reportText); 
     reportFile.close(); 
    } 
    else{ 

     var RCF_file = new File(reportFile); 
     RCF_file.open("w"); 
     RCF_file.write(reportText); 
     RCF_file.close(); 

    } 
    alert('Report Complete'); 
} 

在if(存在)顯然是一樣的,在其他{}代碼 - 不確定它應該是什麼?

回答

1

追加它需要通過追加模式的文件...

reportFile.open("a");