www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Disk space used and free size of a Network share folder in Windows

reply Vino <vino.bheeman hotmail.com> writes:
Hi All,

  Request your help on how to get the disk space used and free 
size of a Network share folder in Windows, tried with getSize but 
it return 0;

eg: Share Name :\\server1\dir1$

From,
Vino.B
Feb 14 2018
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 14/02/2018 12:22 PM, Vino wrote:
 Hi All,
 
   Request your help on how to get the disk space used and free size of a 
 Network share folder in Windows, tried with getSize but it return 0;
 
 eg: Share Name :\\server1\dir1$
 
 From,
 Vino.B
See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx
Feb 14 2018
next sibling parent reply psychoticRabbit <meagain meagain.com> writes:
On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole 
wrote:
 See:
 https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx
============================== public class Program { [DllImport("kernel32.dll")] [return:MarshalAs(UnmanagedType.Bool)] static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes); static void Main() { string dir = "C:\\"; ulong lpFreeBytesAvailable; ulong lpTotalNumberOfBytes; ulong lpTotalNumberOfFreeBytes; GetDiskFreeSpaceEx(dir, out lpFreeBytesAvailable, out lpTotalNumberOfBytes, out lpTotalNumberOfFreeBytes); Console.WriteLine(lpFreeBytesAvailable"); Console.WriteLine(lpTotalNumberOfBytes"); Console.WriteLine(lpFreeBytesAvailable"); } } =================================
Feb 14 2018
parent rikki cattermole <rikki cattermole.co.nz> writes:
On 14/02/2018 1:52 PM, psychoticRabbit wrote:
 On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole wrote:
 See:
 https://msdn.microsoft.com/en-us/library/windows/desktop/aa
64935(v=vs.85).aspx 
============================== public class Program {     [DllImport("kernel32.dll")]         [return:MarshalAs(UnmanagedType.Bool)] static extern bool         GetDiskFreeSpaceEx(string lpDirectoryName,             out ulong lpFreeBytesAvailable,             out ulong lpTotalNumberOfBytes,             out ulong lpTotalNumberOfFreeBytes);     static void Main()     {         string dir = "C:\\";         ulong lpFreeBytesAvailable;         ulong lpTotalNumberOfBytes;         ulong lpTotalNumberOfFreeBytes;         GetDiskFreeSpaceEx(dir, out lpFreeBytesAvailable, out lpTotalNumberOfBytes, out lpTotalNumberOfFreeBytes);         Console.WriteLine(lpFreeBytesAvailable");         Console.WriteLine(lpTotalNumberOfBytes");         Console.WriteLine(lpFreeBytesAvailable");     } } =================================
import core.sys.windows.winbase : GetDiskFreeSpaceEx; Use wstring's and .ptr them and everything should work.
Feb 14 2018
prev sibling parent reply Vino <vino.bheeman hotmail.com> writes:
On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole 
wrote:
 On 14/02/2018 12:22 PM, Vino wrote:
 Hi All,
 
   Request your help on how to get the disk space used and free 
 size of a Network share folder in Windows, tried with getSize 
 but it return 0;
 
 eg: Share Name :\\server1\dir1$
 
 From,
 Vino.B
See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx
Hi Rikki, Wouldn't this be easy to use with std.process: execute package and calling wmic.exe, the only problem is i am not sure hot to get the out put without the headings(Caption FreeSpace,Size) any help on same is much appreciated. import std.process: execute; import std.stdio : writeln; void main () { version(Windows) { auto result = execute(["wmic.exe", "logicaldisk", "get", "size,freespace,caption"]); writeln(result.output); } } Output : Caption FreeSpace Size C: 19702837248 180043665408 H: 85580382208 824633720832 From, Vino.B
Feb 14 2018
next sibling parent FreeSlave <freeslave93 gmail.com> writes:
On Wednesday, 14 February 2018 at 15:24:42 UTC, Vino wrote:
 On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki 
 cattermole wrote:
 [...]
Hi Rikki, Wouldn't this be easy to use with std.process: execute package and calling wmic.exe, the only problem is i am not sure hot to get the out put without the headings(Caption FreeSpace,Size) any help on same is much appreciated. import std.process: execute; import std.stdio : writeln; void main () { version(Windows) { auto result = execute(["wmic.exe", "logicaldisk", "get", "size,freespace,caption"]); writeln(result.output); } } Output : Caption FreeSpace Size C: 19702837248 180043665408 H: 85580382208 824633720832 From, Vino.B
Don't call external processes when you can call a function. Running another process is overhead and not reliable.
Feb 14 2018
prev sibling parent psychoticRabbit <meagain meagain.com> writes:
On Wednesday, 14 February 2018 at 15:24:42 UTC, Vino wrote:
 ...the only problem is i am not sure hot to get the out put 
 without the headings(Caption  FreeSpace,Size) any help on same 
 is much appreciated.
writeln(result.output[38..$]);
Feb 14 2018
prev sibling parent reply Johan Engelen <j j.nl> writes:
On Wednesday, 14 February 2018 at 12:22:09 UTC, Vino wrote:
 Hi All,

  Request your help on how to get the disk space used and free 
 size of a Network share folder in Windows, tried with getSize 
 but it return 0;
See: https://github.com/ldc-developers/ldc/blob/f5b05878de6df2ea4a77c37128ad2eae0266b690/driver/cache_pruning.d#L47-L71 and https://issues.dlang.org/show_bug.cgi?id=16487 cheers, Johan
Feb 15 2018
parent Vino <vino.bheeman hotmail.com> writes:
On Thursday, 15 February 2018 at 20:43:32 UTC, Johan Engelen 
wrote:
 On Wednesday, 14 February 2018 at 12:22:09 UTC, Vino wrote:
 Hi All,

  Request your help on how to get the disk space used and free 
 size of a Network share folder in Windows, tried with getSize 
 but it return 0;
See: https://github.com/ldc-developers/ldc/blob/f5b05878de6df2ea4a77c37128ad2eae0266b690/driver/cache_pruning.d#L47-L71 and https://issues.dlang.org/show_bug.cgi?id=16487 cheers, Johan
Hi All, Thank you very much, was able to successfully use the windows function. From, Vino.B
Feb 16 2018