Appending data to array results in duplicate's.

Vino.B via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 25 09:45:16 PDT 2017


Hi,

  Request your help on the below issue,

Issue : While appending data to a array the data is getting 
duplicated.

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

string[] Subdata;
void main ()
{
  auto dFiles = dirEntries("C:\\Temp\\TEAM", 
SpanMode.shallow).filter!(a => a.isFile).map!(a => tuple(a.name , 
a.timeCreated)).array;
  foreach (d; dFiles)
	     {
		  Subdata ~= d[0];
		  Subdata ~= d[1].toSimpleString;
		  writeln(Subdata);
		  }
}

Output:

["C:\\Temp\\TEAM\\test1.pdf", "2017-Aug-24 18:23:00.8946851"]  - 
duplicate line
["C:\\Temp\\TEAM\\test1.pdf", "2017-Aug-24 18:23:00.8946851", 
"C:\\Temp\\\\TEAM\\test5.xlsx", "2017-Aug-25 23:38:14.486421"]

From,
Vino.B


More information about the Digitalmars-d-learn mailing list