Skip to main content
dublove
Legend
June 26, 2025
Question

How does a script determine if the last modified date of a file is today?

  • June 26, 2025
  • 1 reply
  • 208 views

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.

1 reply

m1b
Community Expert
Community Expert
June 26, 2025

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.');

})();
dublove
dubloveAuthor
Legend
June 26, 2025

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 );

}