Skip to main content
dublove
Legend
Jun 26, 2025 6:20 AM UTC
Question

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

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.

4 replies

m1b
Community Expert
Community Expert
Jun 26, 2025 9:12 AM UTC

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

})();
Translate
dublove
dubloveAuthor
Legend
Jun 26, 2025 12:24 PM UTC

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

}

 

Translate