Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
February 14, 2018 Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
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 |
February 14, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | 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 |
February 14, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | 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 any idea on how I'd convert this C# code to D? ============================== 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"); } } ================================= |
February 14, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to psychoticRabbit | 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/aa364935(v=vs.85).aspx
>>
>
> any idea on how I'd convert this C# code to D?
>
> ==============================
> 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.
|
February 14, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | 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
|
February 14, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | 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.
|
February 15, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | 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..$]);
|
February 15, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vino | 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 |
February 17, 2018 Re: Disk space used and free size of a Network share folder in Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Engelen | 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
|
Copyright © 1999-2021 by the D Language Foundation