Copy link to clipboard
Copied
For example, I want to determine the last modified date of my.json.
If it is not today, I perform operation A, if it is, I skip operation A. Execute
Thank you very much.
Copy link to clipboard
Copied
Here's one way:
(function () {
var file = File.openDialog();
if (!file)
return;
var modified = file.modified,
today = new Date();
if (
modified.getFullYear() === today.getFullYear()
&& modified.getMonth() === today.getMonth()
&& modified.getDate() === today.getDate()
)
alert('The file "' + decodeURI(file.name) + '" was modified today.');
else
alert('The file "' + decodeURI(file.name) + '" was modified before today.');
})();
Copy link to clipboard
Copied
Hi m1b.
Thank you.
I don't open the file, I still want to check if the last modified date of my.json is today.
The myJSONpath below doesn't seem right.
myJSONpath=decodeURI(myJSONpath );
Get this:
function getJson() {
myJSONObject = evalJSON(File($.fileName).parent.parent + '/PubLib/my.json');
if (!myJSONObject)
alert('Failed to load JSON.');
myJSONpath = (File($.fileName).parent.parent + '/PubLib/my.json');
myJSONpath=decodeURI(myJSONpath );
}
Copy link to clipboard
Copied
I've often tried to mess with it, but for some reason it suggests that there's an error in line 49
//@include '../PubLib/pubLib.jsx';
//@include '../PubLib/json.jsx';
function getJson() {
myJSONObject = evalJSON(File($.fileName).parent.parent + '/PubLib/my.json');
if (!myJSONObject)
alert('Failed to load JSON.');
var str = decodeURI((File($.fileName).parent.parent + '/PubLib/my.json'));
//alert(myJSONObject);
path1 = str.substring(1, 2);
//alert(path1);
path2 = str.substring(2, str.length - 0);
myJSONpath = path1 + ':' + path2;
//alert(myJSONpath);
}
function readFile(path) {
var file = File(path);
if (!file.exists)
return;
file.open('r');
var content = file.read();
file.close();
return content;
};
function evalJSON(path) {
json = readFile(path);
if (!json)
return;
return JSON.eval(json);
};
getJson();
lastMoDate();
function lastMoDate() {
var file = myJSONpath;
//alert(myJSONpath);
if (!file)
return;
var modified = file.modified,
today = new Date();
alert(file);
if (
modified.getFullYear() === today.getFullYear()
&& modified.getMonth() === today.getMonth()
&& modified.getDate() === today.getDate()
) {
alert('The file "' + decodeURI(file.name) + '" was modified today.');
}
else {
alert('The file "' + decodeURI(file.name) + '" was modified before today.');
}
}
Copy link to clipboard
Copied
I modified the code above:
myJSONpath = path1 + ':' + path2;
It should not contain file:/
Find more inspiration, events, and resources on the new Adobe Community
Explore Now