我想獲取目錄的內容,按修改時間排序。我認爲在dirEntries
調用中沒有辦法直接執行此操作,所以我的策略是收集所有文件時間和名稱,然後按鎖步排序這兩個數組。我想不出如何將sysTime
轉換爲整數。
問題2:我無法弄清楚如何並行排序兩個數組。在Dlang中獲取按修改日期排序的目錄列表
與在d每一個問題,這是不可能找出如何做到這一點:(
這裏是我的代碼:
import std.file;
import std.stdio : writeln;
import std.algorithm;
import std.datetime;
void main() {
string[] myFiles;
double[] myTimes;
foreach (DirEntry e; dirEntries("c:/users/istaffel/", SpanMode.shallow)) {
// calculate unix time (this doesn't work)
auto dur = (cast(Date)e.timeLastModified) - Date(1970,1,1);
// store modified time and filename
myTimes ~= dur.seconds;
myFiles ~= e.name;
}
// now find a way to sort myFiles in order of ascending myTimes...
// print in order
for (int i = 0; i < myTimes.length; i++) {
writeln(myTimes[i], " ", myFiles[i]);
}
}
哇。這次真是萬分感謝。我認爲在D中發生的事情太多了,很難立足。 – 2013-03-06 21:57:57
我有Alexandrescu關於D的書,但是它的大部分內容都陡峭的學習曲線。我會給你提供一個鏡頭的書。 – 2013-03-06 21:58:44