Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

I need to run a check on a folder to see when it was last modified. By this I mean the last time it, or any of the files it contains where last modified.

I have tried two ways so far:

  1. using the stat() function on the folder, and then grabbing mtime

    $stat = stat("directory/path/"); echo $stat["mtime"]; $stat = stat("directory/path/"); echo $stat["mtime"];

  2. using the filemtime()filemtime() function on the folder

    echo (filemtime("directory/path/")); echo (filemtime("directory/path/"));

Both of these methods return the same value, and this value does not change if I update one of the files. I am guessing this is because the folder structure itself does not change, only the content of one of the files.

I guess I could loop through all the files in the directory and check their modification dates, but there are potentially a lot of files and this doesn't seem very efficient.

Can anyone suggest how I might go about getting a last modification time for a folder and its content in an efficient way?

I need to run a check on a folder to see when it was last modified. By this I mean the last time it, or any of the files it contains where last modified.

I have tried two ways so far:

  1. using the stat() function on the folder, and then grabbing mtime

    $stat = stat("directory/path/"); echo $stat["mtime"];

  2. using the filemtime() function on the folder

    echo (filemtime("directory/path/"));

Both of these methods return the same value, and this value does not change if I update one of the files. I am guessing this is because the folder structure itself does not change, only the content of one of the files.

I guess I could loop through all the files in the directory and check their modification dates, but there are potentially a lot of files and this doesn't seem very efficient.

Can anyone suggest how I might go about getting a last modification time for a folder and its content in an efficient way?

I need to run a check on a folder to see when it was last modified. By this I mean the last time it, or any of the files it contains where last modified.

I have tried two ways so far:

  1. using the stat() function on the folder, and then grabbing mtime

    $stat = stat("directory/path/"); echo $stat["mtime"];

  2. using the filemtime() function on the folder

    echo (filemtime("directory/path/"));

Both of these methods return the same value, and this value does not change if I update one of the files. I am guessing this is because the folder structure itself does not change, only the content of one of the files.

I guess I could loop through all the files in the directory and check their modification dates, but there are potentially a lot of files and this doesn't seem very efficient.

Can anyone suggest how I might go about getting a last modification time for a folder and its content in an efficient way?

Source Link
Finglish
  • 10k
  • 15
  • 79
  • 118

How can I find when a folders content was last modified efficiently in php

I need to run a check on a folder to see when it was last modified. By this I mean the last time it, or any of the files it contains where last modified.

I have tried two ways so far:

  1. using the stat() function on the folder, and then grabbing mtime

    $stat = stat("directory/path/"); echo $stat["mtime"];

  2. using the filemtime() function on the folder

    echo (filemtime("directory/path/"));

Both of these methods return the same value, and this value does not change if I update one of the files. I am guessing this is because the folder structure itself does not change, only the content of one of the files.

I guess I could loop through all the files in the directory and check their modification dates, but there are potentially a lot of files and this doesn't seem very efficient.

Can anyone suggest how I might go about getting a last modification time for a folder and its content in an efficient way?