Container Array

Vino.B via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 7 08:07:56 PDT 2017


On Thursday, 7 September 2017 at 14:26:08 UTC, Ali Çehreli wrote:
> On 09/07/2017 03:56 AM, Vino.B wrote:
>
>> writeln(coCleanFiles);
>
> Access the elements by taking a slice of the container:
>
>     writeln(coCleanFiles[]);
>
> Ali

Hi Ali,

  Thank you very much, was ablee to resolve this issue and now 
facing a new issue as the below code is not working as expected. 
The below code has to list the folders and their size's.

import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;

Array!(Tuple!(string, ulong)) coSizeDirList () {
	string FFs = "C:\\Temp\\TEST1\\BACKUP";
	int SizeDir = 10;
	ulong subdirTotal;
	ulong subdirTotalGB;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));
     foreach (d; dFiles) {
				auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
				foreach(f; parallel(SdFiles, 1)) { subdirTotal += f.fold!((a, 
b) => a + b); }
					subdirTotalGB = (subdirTotal/1024/1024);
					if (subdirTotalGB > SizeDir) { auto Subdata = 
Array!(Tuple!(string, ulong))(dFiles ~ subdirTotalGB); }
					 subdirTotal = 0;
		    }
			return Subdata;
}

void main () {
writeln (coSizeDirList[]);
}


More information about the Digitalmars-d-learn mailing list