On Monday, 11 December 2017 at 19:23:40 UTC, Seb wrote:
On Monday, 11 December 2017 at 16:15:14 UTC, Vino wrote:
On Monday, 11 December 2017 at 15:54:11 UTC, Biotronic wrote:
  [...]

Hi Biotronic,

I tried your code with multiple folder's , but no luck the output is not sorted.

Program:
import std.algorithm: filter, map, sort;
import std.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln, writeln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs = ["C:\\Temp\\sapnas2\\BACKUP", "C:\\Temp\\sapnas2\\EXPORT", "C:\\Temp\\sapnas2\\PROD_TEAM"];
auto sorted = FFs
.map!(a => dirEntries(a, SpanMode.shallow))
.join
.filter!(a => a.isDir)
.map!(a => tuple(a.name, a.timeCreated.toSimpleString[0 .. 20]))
.array
.sort!((a,b) => a[1] > b[1]);
writefln("%( %( %-63s %s %) \n%)", sorted);
}

From,
Vino.B

Your program still contains toSimpleString in the sort lambda. Have you, as suggested, removed it? As Biotronic explained, sorting on the string representation of dates can't work.

Hi,

Yes, I have changed the code as below, and removed the toSimpleString, even then no luck.

Code:
import std.algorithm;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln, writeln;
import std.typecons: Tuple, tuple;
import std.range: chain;

void main () {
auto FFs = ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT", "C:\\Temp\\PROD_TEAM"];
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, a.timeCreated))); writefln("%(%-(%-63s %s %)\n%)", chain(dFiles[]).sort!((a, b) => a[1] < b[1]));
}
}

Output
C:\Temp\BACKUP\DND3 2017-Sep-05 14:31:00.7037169 C:\Temp\BACKUP\dir1 2017-Sep-06 16:06:42.7223837 C:\Temp\BACKUP\dir2 2017-Sep-09 22:44:11.7604069 C:\Temp\BACKUP\dir3 2017-Dec-10 06:56:07.5122231 C:\Temp\BACKUP\t1 2017-Dec-11 04:10:02.6413853

C:\Temp\EXPORT\DND6 2017-Sep-05 14:31:00.8909172 C:\Temp\PROD_TEAM\DND1 2017-Sep-05 14:31:01.8269189

Required Output:
C:\Temp\BACKUP\DND3 2017-Sep-05 14:31:00.7037169 C:\Temp\EXPORT\DND6 2017-Sep-05 14:31:00.8909172 C:\Temp\PROD_TEAM\DND1 2017-Sep-05 14:31:01.8269189 C:\Temp\BACKUP\dir1 2017-Sep-06 16:06:42.7223837 C:\Temp\BACKUP\dir2 2017-Sep-09 22:44:11.7604069 C:\Temp\BACKUP\dir3 2017-Dec-10 06:56:07.5122231 C:\Temp\BACKUP\t1 2017-Dec-11 04:10:02.6413853

From,
Vino.B

Reply via email to