Thread overview | |||||
---|---|---|---|---|---|
|
August 19, 2017 Folder Size | ||||
---|---|---|---|---|
| ||||
Hi All, I have written a small program to find the size of folder's , but the output is not as expected, hence request your help and advice on any techniques to reduce the run time of the program. Requirement: The script has to scan several file system ("C:\\Temp\\TEAM","C:\\Temp\\PROD_TEAM", "C:\\Temp\\BACKUP") Display only the sub folder level 1 name whose name should not contain *DND* and size dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")) Eg: C:\Temp\TEAM\USER_BACKUP , C:\Temp\PROD_TEAM\PROD_BACKUP , C:\Temp\BACKUP\SUPPORT_BACKUP Need the folder name and size of each folder under C:\Temp\TEAM\USER_BACKUP , C:\Temp\PROD_TEAM\PROD_BACKUP , C:\Temp\BACKUP\SUPPORT_BACKUP -------- Program -------- import std.file: dirEntries, isFile, SpanMode; import std.stdio: writeln; import std.algorithm: filter; import std.array: array; import std.path; auto AgedDirlst = [ "C:\\Temp\\TEAM\\USER_BACKUP" , "C:\\Temp\\PROD_TEAM\\PROD_BACKUP" , "C:\\Temp\\BACKUP\\SUPPORT_BACKUP" ]; void main () { foreach (string i; AgedDirlst[0 .. $]) { auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array; foreach (d; dFiles) { auto SdFiles = dirEntries(d, SpanMode.depth).array; foreach (f; SdFiles) writeln(f.dirName, "\t", f.size); } } writeln("*************************************************************************************"); } -------- Output: -------- C:\Temp\TEAM\USER_BACKUP\DIR1 41129 C:\Temp\TEAM\USER_BACKUP\DIR1\dir3 68 C:\Temp\TEAM\USER_BACKUP\DIR1 0 C:\Temp\TEAM\USER_BACKUP\DIR2\dir4 3410 C:\Temp\TEAM\USER_BACKUP\DIR2\dir4 2277663 C:\Temp\TEAM\USER_BACKUP\DIR2 0 C:\Temp\TEAM\USER_BACKUP\DIR2 1156 C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 41129 C:\Temp\PROD_TEAM\PROD_BACKUP\dir1\dir3 68 C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 0 C:\Temp\PROD_TEAM\PROD_BACKUP\dir1\DND1 36590125 C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 0 C:\Temp\PROD_TEAM\PROD_BACKUP\dir2\dir4 3410 C:\Temp\PROD_TEAM\PROD_BACKUP\dir2 0 C:\Temp\PROD_TEAM\PROD_BACKUP\dir2 1156 C:\Temp\BACKUP\SUPPORT_BACKUP\dir1\DND1 36590125 C:\Temp\BACKUP\SUPPORT_BACKUP\dir1 0 C:\Temp\BACKUP\SUPPORT_BACKUP\dir2\DND2 1156 ------------------- Required Output ------------------- C:\Temp\TEAM\USER_BACKUP\DIR1 41197 (41129+68) C:\Temp\TEAM\USER_BACKUP\DIR2 2282229 (3410+2277663+1156) C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 36631322 (41129+68+36590125) C:\Temp\PROD_TEAM\PROD_BACKUP\dir2 4566 (3410+1156) C:\Temp\BACKUP\SUPPORT_BACKUP\dir1 36590125 C:\Temp\BACKUP\SUPPORT_BACKUP\dir2 1156 From, Vino.B |
August 21, 2017 Re: Folder Size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino.B | On Saturday, 19 August 2017 at 14:19:39 UTC, Vino.B wrote: > Hi All, > > I have written a small program to find the size of folder's , but the output is not as expected, hence request your help and advice on any techniques to reduce the run time of the program. > > Requirement: > The script has to scan several file system > > ("C:\\Temp\\TEAM","C:\\Temp\\PROD_TEAM", "C:\\Temp\\BACKUP") > > Display only the sub folder level 1 name whose name should not contain *DND* and size > > dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")) > > Eg: C:\Temp\TEAM\USER_BACKUP , C:\Temp\PROD_TEAM\PROD_BACKUP , C:\Temp\BACKUP\SUPPORT_BACKUP > > Need the folder name and size of each folder under > C:\Temp\TEAM\USER_BACKUP , C:\Temp\PROD_TEAM\PROD_BACKUP , C:\Temp\BACKUP\SUPPORT_BACKUP > -------- > Program > -------- > import std.file: dirEntries, isFile, SpanMode; > import std.stdio: writeln; > import std.algorithm: filter; > import std.array: array; > import std.path; > > auto AgedDirlst = [ "C:\\Temp\\TEAM\\USER_BACKUP" , "C:\\Temp\\PROD_TEAM\\PROD_BACKUP" , "C:\\Temp\\BACKUP\\SUPPORT_BACKUP" ]; > > void main () > { > foreach (string i; AgedDirlst[0 .. $]) > { > auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array; > foreach (d; dFiles) > { > auto SdFiles = dirEntries(d, SpanMode.depth).array; > foreach (f; SdFiles) > writeln(f.dirName, "\t", f.size); > > } > } > writeln("*************************************************************************************"); > } > -------- > Output: > -------- > C:\Temp\TEAM\USER_BACKUP\DIR1 41129 > C:\Temp\TEAM\USER_BACKUP\DIR1\dir3 68 > C:\Temp\TEAM\USER_BACKUP\DIR1 0 > > C:\Temp\TEAM\USER_BACKUP\DIR2\dir4 3410 > C:\Temp\TEAM\USER_BACKUP\DIR2\dir4 2277663 > C:\Temp\TEAM\USER_BACKUP\DIR2 0 > C:\Temp\TEAM\USER_BACKUP\DIR2 1156 > > C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 41129 > C:\Temp\PROD_TEAM\PROD_BACKUP\dir1\dir3 68 > C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 0 > C:\Temp\PROD_TEAM\PROD_BACKUP\dir1\DND1 36590125 > C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 0 > > C:\Temp\PROD_TEAM\PROD_BACKUP\dir2\dir4 3410 > C:\Temp\PROD_TEAM\PROD_BACKUP\dir2 0 > C:\Temp\PROD_TEAM\PROD_BACKUP\dir2 1156 > > C:\Temp\BACKUP\SUPPORT_BACKUP\dir1\DND1 36590125 > C:\Temp\BACKUP\SUPPORT_BACKUP\dir1 0 > C:\Temp\BACKUP\SUPPORT_BACKUP\dir2\DND2 1156 > ------------------- > Required Output > ------------------- > C:\Temp\TEAM\USER_BACKUP\DIR1 41197 (41129+68) > C:\Temp\TEAM\USER_BACKUP\DIR2 2282229 (3410+2277663+1156) > C:\Temp\PROD_TEAM\PROD_BACKUP\dir1 36631322 (41129+68+36590125) > C:\Temp\PROD_TEAM\PROD_BACKUP\dir2 4566 (3410+1156) > C:\Temp\BACKUP\SUPPORT_BACKUP\dir1 36590125 > C:\Temp\BACKUP\SUPPORT_BACKUP\dir2 1156 > > From, > Vino.B Keep a variable to add the sizes of subdirs auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array; ulong subdirTotal = 0; foreach (d; dFiles) { subdirTotal = 0; auto SdFiles = dirEntries(d, SpanMode.depth).array; foreach(f; SdFiles) { subdirTotal += f.size; } writeln(d, "\t", subdirTotal); } -- Aravinda http://aravindavk.in |
August 21, 2017 Re: Folder Size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Aravinda VK | On Monday, 21 August 2017 at 08:57:52 UTC, Aravinda VK wrote:
> On Saturday, 19 August 2017 at 14:19:39 UTC, Vino.B wrote:
>> [...]
>
> Keep a variable to add the sizes of subdirs
>
> auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array;
> ulong subdirTotal = 0;
> foreach (d; dFiles)
> {
> subdirTotal = 0;
> auto SdFiles = dirEntries(d, SpanMode.depth).array;
> foreach(f; SdFiles) {
> subdirTotal += f.size;
> }
> writeln(d, "\t", subdirTotal);
> }
>
> --
> Aravinda
> http://aravindavk.in
Hi Aravinda,
Thank you for the idea, but i have to tweek my code toas below to get the required output and now I am able to get the required output
auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array;
foreach (d; dFiles)
{
auto SdFiles = dirEntries(d, SpanMode.depth).array;
//auto entry = SdFiles.front;
foreach (f; SdFiles)
{
subdirTotal += f.size;
}
ulong subdirTotalGB = (subdirTotal/1000/1000);
writefln("%-63s %s %s", d, subdirTotalGB, " MB");
subdirTotal = 0;
}
From,
Vino.B
|
Copyright © 1999-2021 by the D Language Foundation