02-22-2018 04:33 AM - edited 02-22-2018 04:35 AM
I'm trying to get the Folder's "Size on disk". It's working with "du.exe" using "System Exec.vi".
I don't want to use System exec.vi as it increases dependency.
DLLs, .Net Constructors, Property nodes etc is fine.
OS and S/W Info: Windows 10 - 64 Bits and LabVIEW 17.
Note: You can find all details related to du.exe here.
Please suggest an optimized and correct way of implementation.
02-22-2018 04:45 AM
There is a VI called "Recursive File List.vi" in the advanced palette of File I/O. It gives you a list of all files in a directory and its subdirectories. Iterate through this array and accumulate file sizes.
02-22-2018 05:56 AM
Dave, Thanks for your immediate response.
I tried the way you suggested but its giving me only Size of Folder whereas I want "Size on disk" of that particular folder.
02-22-2018 07:41 AM
Did you try this?
02-22-2018 10:12 AM
The problem is that Size on Disk depends on the block size of your drive, which can vary between drives. There may be some low level OS calls that can return the block size. Do a search for "get file size on disk" and see what you come up with.
02-22-2018 11:36 PM - edited 02-22-2018 11:36 PM
Dave,
Yes I tried same snippet. I'm getting "Size" of folder, but not getting "Size on disk". Does "Recursive File List.vi" doing anything different which will provide me "Size on disk"?.
According to my observation its same like using list folder.vi, building file paths and after that we are using same "get file size" function to get the size and then adding it together to get overall size.
02-23-2018 03:00 AM
Try this:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364930(v=vs.85).aspx
Description seems to indicate it will get actual used bytes of hard disk for a file. Some debate about it though, but saw no resolution if it works on uncompressed files. Again, the description seems to indicate it will.
If that doesn't work this will give you the cluster size for the hard drive:
https://msdn.microsoft.com/en-us/library/aa364935(VS.85).aspx
You'll then have to get the size of each file and round up to the nearest round count of that cluster size, adding them up as you go.
Matthew
02-23-2018 05:03 AM
"Recursive File List.vi" just gives you conveniently the path to all files in folders and subfolders. The key is "get file size" to add up the single sizes.
There is the advice to round up to next cluster size for each file, but this doesn't work for me either. To illustrate this:
Windows Calculation of File Sizes & Disk Size
fsutil information with 3 different cluster/sector sizes
result of disc usage calculation for 3 cluster/sector sizes, none of them match the value in the first image, but file size sum does
The code
This gets confusing...
02-23-2018 06:07 AM
The reported size on disk can be divided by no power of 2 bigger than 16.
Quite peculiar. I tried with several local and network folders: sizes are all divisible by 512.
Windows Calculation of File Sizes & Disk Size
02-23-2018 07:41 AM
@atul_ghumade wrote:
I'm trying to get the Folder's "Size on disk". It's working with "du.exe" using "System Exec.vi".
I don't want to use System exec.vi as it increases dependency.
DLLs, .Net Constructors, Property nodes etc is fine.
Wait. What? You don't want to use your working solution because it increases dependencies... but you're ok with creating a dependency on a dll? Stop being silly and use sys exec. There's no reason to use a more complex dependency when you already have something built into LV that works for your need.