문제

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 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top