rschirin
rschirin

Reputation: 2049

how can I get only last modified date

how can I get ONLY the filename and its last modified date of the files contained into a folder (even subfolders)

I want this kind of result:

path/filename  lastmodified_date

or

filename lastmodified_date

Upvotes: 0

Views: 105

Answers (2)

Winston
Winston

Reputation: 1805

You need to get list files using glob() or scandir() after, you need to get last modified dates using filemtime().

Try this code

$files = scandir('./'); // Get list files current dir
$times = array_map('filemtime', $files); // Get last modified date each file
$result = array_combine($files, $times); // Set file names as array index and times as value

Now we have array with filenames and last modified date its. You can get data by using foreach($result as $filename => $date) $data will have unix-time date.

Upvotes: 0

William Pursell
William Pursell

Reputation: 212494

find /p/a/t/h -type f -printf '%p %t\n'

Will show you the name and mtime of every file below /p/a/t/h. To get an epoch time instead of the long form, use:

find /p/a/t/h -type f -printf '%p %T@\n'

Check the documentation for find for instructions on how to change the format of the timestamp.

Upvotes: 1

Related Questions