JavaScript:保存.CSV内部文件夹,并带有今天的日期



每天我运行shell脚本以创建具有当前日期的新文件夹。

使用shell,即使文件夹的名称经常更改,也可以在该文件夹中保存任何内容非常容易。

例如:currentDate=/path/$(date +%Y%m%d)我只是在Path中放置一个date变量。

我想,JavaScript会相似吗?

所以问题是,JavaScript语法中是否有一种方法可以访问名称不断更改的文件夹?

以下似乎不起作用:

// Create the log file with Today's Date
folderName = "~/Desktop/"
var now = new Date();
var logfile_name = now.getFullYear() + "-"+ now.getMonth() + "-" + now.getDate()
var fileOut = new File(folderName+logfile_name+"/"+'RT3.csv');
if (!fileOut.exists) {
  fileOut.open("w");
  fileOut.writeln(",", docRef.name);
} else {
  fileOut.open("a");
  fileOut.writeln(",", docRef.name);
}
fileOut.close();

任何建议都将不胜感激。

尝试一下,它应该在桌面上创建当前日期的文件夹,并应在.csv

上添加当前文档名称
var folderName = "~/Desktop/";
var now = new Date();
var logfile_name = now.getFullYear() + "-"+ now.getMonth() + "-" + now.getDate();
var f = new Folder(folderName + logfile_name);
if ( ! f.exists ) {
    f.create();
}
var docRef=app.activeDocument;
var file = new File(f+"/"+'RT3.csv');
file.open('w');
file.writeln(",",docRef.name);
file.close();

您错过的是我认为是否存在检查文件夹是否存在:)享受!

edit:好吧,您甚至不必使用shell来创建文件夹,因为如果不存在此Photoshop脚本,则会自动执行:(

最新更新