September 11, 2017
On Sunday, 10 September 2017 at 23:10:20 UTC, Ali Çehreli wrote:
> On 09/10/2017 09:53 AM, Vino.B wrote:
>
> > auto coSizeDirList (string FFs, int SizeDir) {
>
> > //alias DirSizeList = typeof(coSizeDirList());
>
> I worked with a version of coSizeDirList() that did not take any parameters. (Could be from an earlier post of yours.)
>
> In this case, you can must use a compilable expression. Since coSizeDirList above takes a string and int, you can get its return value like this:
>
>   alias DirSizeList = typeof(coSizeDirList(string.init, int.init))
>
> The following can work as well:
>
>   alias DirSizeList = typeof(coSizeDirList("", 42))
>
> However, there are other compilation errors when I do that.
>
> Ali

Hi Ali,

The issue occurs at the line "MSresult.get ~= MSizeDirListData" when we try to append data the error message is as below, if we change this line to "MSresult.get = MSizeDirListData" then the code complies without any issue but the output is empty.

T2.d(41): Error: cannot append type Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) to type Tuple!(RangeT!(Array!string), RangeT!(Array!ulong))


Code:

import core.stdc.stdlib: exit;
import std.algorithm: all, among, filter, map, setDifference, sort, uniq, each, joiner;
import std.array: appender, join;
import std.container.array;
import std.conv: to;
import std.datetime.systime: Clock, days, SysTime;
import std.file: SpanMode, dirEntries, exists, isFile, mkdir, remove, rmdirRecurse;
import std.getopt;
import std.parallelism: parallel, task, taskPool;
import std.path: absolutePath, baseName, dirName, isValidFilename, isValidPath, globMatch;
import std.range: empty;
import std.stdio: File, writefln, writeln;
import std.string: chomp, chop, isNumeric, split, strip;
import std.typecons: tuple, Tuple;
import std.uni: isAlpha, toLower, isWhite;

auto coSizeDirList (string FFs, int SizeDir) {
	ulong subdirTotal;
	ulong subdirTotalGB;
	Array!string Subdir;
	Array!ulong Subsize;
	auto dFiles = Array!string ((dirEntries(FFs, SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));
    foreach (d; dFiles[]) {
				auto SdFiles = Array!ulong(dirEntries(d, SpanMode.depth).map!(a => a.size));
				foreach(f; SdFiles[]) { subdirTotal += f; }
				subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d; Subsize ~= subdirTotalGB; }
				if (subdirTotalGB > SizeDir)
				subdirTotal = 0;
		    }
			return tuple (Subdir[], Subsize[]);
}

void ptSizeDirList (string[] SizeDirlst, int SizeDir) {
 alias DirSizeList = typeof(coSizeDirList(string.init, ulong.init));
 auto MSresult = taskPool.workerLocalStorage!DirSizeList();
 foreach (string Fs; parallel(SizeDirlst[0 .. $], 1)) {
			auto FFs = Fs.strip;
			auto MSizeDirList = task(&coSizeDirList, FFs, SizeDir);
			MSizeDirList.executeInNewThread();
			auto MSizeDirListData = MSizeDirList.workForce;
			//MSresult.get ~= MSizeDirListData;
			MSresult.get = MSizeDirListData;
			}
		foreach(i; MSresult.tupleof)
		//if (!i.empty) { writefln("%(%-(%-63s %)\n%)", i[].sort!((a,b) => a[0] < b[0]).uniq); }
		writeln(i);
	}

void main () {
string SizeDirlst = "C:\\Temp\\TEAM\\BACKUP";
int SizeDir = 1;
coSizeDirList(SizeDirlst, SizeDir);
}

From,
Vino.B
September 11, 2017
On Monday, 11 September 2017 at 08:55:21 UTC, Vino.B wrote:
> On Sunday, 10 September 2017 at 23:10:20 UTC, Ali Çehreli wrote:
>> On 09/10/2017 09:53 AM, Vino.B wrote:
>>
>> > auto coSizeDirList (string FFs, int SizeDir) {
>>
>> > //alias DirSizeList = typeof(coSizeDirList());
>>
>> I worked with a version of coSizeDirList() that did not take any parameters. (Could be from an earlier post of yours.)
>>
>> In this case, you can must use a compilable expression. Since coSizeDirList above takes a string and int, you can get its return value like this:
>>
>>   alias DirSizeList = typeof(coSizeDirList(string.init, int.init))
>>
>> The following can work as well:
>>
>>   alias DirSizeList = typeof(coSizeDirList("", 42))
>>
>> However, there are other compilation errors when I do that.
>>
>> Ali
>
> Hi Ali,
>
> The issue occurs at the line "MSresult.get ~= MSizeDirListData" when we try to append data the error message is as below, if we change this line to "MSresult.get = MSizeDirListData" then the code complies without any issue but the output is empty.
>
> T2.d(41): Error: cannot append type Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) to type Tuple!(RangeT!(Array!string), RangeT!(Array!ulong))
>
>
> Code:
>
> import core.stdc.stdlib: exit;
> import std.algorithm: all, among, filter, map, setDifference, sort, uniq, each, joiner;
> import std.array: appender, join;
> import std.container.array;
> import std.conv: to;
> import std.datetime.systime: Clock, days, SysTime;
> import std.file: SpanMode, dirEntries, exists, isFile, mkdir, remove, rmdirRecurse;
> import std.getopt;
> import std.parallelism: parallel, task, taskPool;
> import std.path: absolutePath, baseName, dirName, isValidFilename, isValidPath, globMatch;
> import std.range: empty;
> import std.stdio: File, writefln, writeln;
> import std.string: chomp, chop, isNumeric, split, strip;
> import std.typecons: tuple, Tuple;
> import std.uni: isAlpha, toLower, isWhite;
>
> auto coSizeDirList (string FFs, int SizeDir) {
> 	ulong subdirTotal;
> 	ulong subdirTotalGB;
> 	Array!string Subdir;
> 	Array!ulong Subsize;
> 	auto dFiles = Array!string ((dirEntries(FFs, SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));
>     foreach (d; dFiles[]) {
> 				auto SdFiles = Array!ulong(dirEntries(d, SpanMode.depth).map!(a => a.size));
> 				foreach(f; SdFiles[]) { subdirTotal += f; }
> 				subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d; Subsize ~= subdirTotalGB; }
> 				if (subdirTotalGB > SizeDir)
> 				subdirTotal = 0;
> 		    }
> 			return tuple (Subdir[], Subsize[]);
> }
>
> void ptSizeDirList (string[] SizeDirlst, int SizeDir) {
>  alias DirSizeList = typeof(coSizeDirList(string.init, ulong.init));
>  auto MSresult = taskPool.workerLocalStorage!DirSizeList();
>  foreach (string Fs; parallel(SizeDirlst[0 .. $], 1)) {
> 			auto FFs = Fs.strip;
> 			auto MSizeDirList = task(&coSizeDirList, FFs, SizeDir);
> 			MSizeDirList.executeInNewThread();
> 			auto MSizeDirListData = MSizeDirList.workForce;
> 			//MSresult.get ~= MSizeDirListData;
> 			MSresult.get = MSizeDirListData;
> 			}
> 		foreach(i; MSresult.tupleof)
> 		//if (!i.empty) { writefln("%(%-(%-63s %)\n%)", i[].sort!((a,b) => a[0] < b[0]).uniq); }
> 		writeln(i);
> 	}
>
> void main () {
> string SizeDirlst = "C:\\Temp\\TEAM\\BACKUP";
> int SizeDir = 1;
> coSizeDirList(SizeDirlst, SizeDir);
> }
>
> From,
> Vino.B

Hi Ali,


  At last was able to resolve the issue, thank you very much for all your help. below is the working code.

Program:
import core.stdc.stdlib: exit;
import std.algorithm: all, among, filter, map, setDifference, sort, uniq, each, joiner;
import std.array: appender, join;
import std.container.array;
import std.conv: to;
import std.datetime.systime: Clock, days, SysTime;
import std.file: SpanMode, dirEntries, exists, isFile, mkdir, remove, rmdirRecurse;
import std.getopt;
import std.parallelism: parallel, task, taskPool;
import std.path: absolutePath, baseName, dirName, isValidFilename, isValidPath, globMatch;
import std.range: empty, zip;
import std.stdio: File, writefln, writeln;
import std.string: chomp, chop, isNumeric, split, strip;
import std.typecons: tuple, Tuple;
import std.uni: isAlpha, toLower, isWhite;

auto coSizeDirList (string FFs, ulong SizeDir) {
	ulong subdirTotal;
	ulong subdirTotalGB;
	Array!string Subdir;
	Array!ulong Subsize;
	auto dFiles = Array!string ((dirEntries(FFs, SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));
    foreach (d; dFiles[]) {
				auto SdFiles = Array!ulong(dirEntries(d, SpanMode.depth).map!(a => a.size));
				foreach(f; SdFiles[]) { subdirTotal += f; }
				subdirTotalGB = (subdirTotal/1024/1024);
				if (subdirTotalGB > SizeDir) { Subdir ~= d; Subsize ~= subdirTotalGB; }
				subdirTotal = 0;
		    }
			return tuple (Subdir[], Subsize[]);
}

void ptSizeDirList (Array!string SizeDirlst, ulong SizeDir) {
 alias DirSizeList = typeof(coSizeDirList(string.init, ulong.init));
 auto MSresult = taskPool.workerLocalStorage!DirSizeList();
 foreach (string Fs; parallel(SizeDirlst[0 .. $], 1)) {
			auto FFs = Fs.strip;
			auto MSizeDirList = task(&coSizeDirList, FFs, SizeDir);
			MSizeDirList.executeInNewThread();
			auto MSizeDirListData = MSizeDirList.workForce;
			MSresult.get = MSizeDirListData;
			}
		foreach(i; MSresult.toRange)
		if (!i[0].empty && !i[1].empty) { foreach(e; zip(i[0], i[1])) writefln("%-63s %8s", e[0],e[1]); }
	}

void main () {
auto SizeDirlst = Array!string("C:\\Temp\\sapnas2\\BACKUP", "C:\\Temp\\sapnas2\\PROD_TEAM");
ulong SizeDir = 10;
ptSizeDirList(SizeDirlst, SizeDir);
}

From,
Vino.B
1 2
Next ›   Last »