Get the latest file in C:\file:
$files = glob('c:/file/*.*');
$files = array_combine($files, array_map('filectime', $files));
arsort($files);
echo key($files); // the filename
Вопрос
What is the best way to get the latest created file in a specific directory.
Say I have a folder named: csv_files that is located in C:
// Now the content in my C://csv_files/:
-filesample_20140509-1399602430.csv
-sample_20140509-1399603954.csv
-sample_20140509-1399608552.csv
Now what I want is to get the latest of sample_*
and based from the above content the latest is sample_20140509-1399608552.csv
. How can I accomplish this?
Решение
Get the latest file in C:\file:
$files = glob('c:/file/*.*');
$files = array_combine($files, array_map('filectime', $files));
arsort($files);
echo key($files); // the filename