Example Code

Calculating the Size on Disk of a Directory (Folder) in Windows

Code and Documents

Attachment

It is often useful to calculate the amout of Hard Drive space of a Windows Directory (folder) from within LabVIEW.  Often, this can be used for diagnosing whether a hard drive is almost full, if new data has been correctly saved into a location, or for creating a customized copy/paste progress bar.  It is possible to code the entire application in LabVIEW, however, other free tools that already perform this action could be integrated into LabVIEW to reduce development time.

The Windows Sysinternals website, by Microsoft, provides additional utilities for developers.  One application, Disk Usage v1.34 (DU.exe), can be used for returning the size of a directory on the hard drive.  Once downloaded from the website and unzipped, the file DU.exe can be pasted into the folder C:\Windows\System32.  Any EXE in this directory can be called directly from the Windows Command Prompt.  In LabVIEW, Command Prompt can be automated using the System Exec VI.  This example calls DU.exe with the correct parameters in order to return the size of any directory on the hard drive, without using LabVIEW VIs from the File I/O palette.  The example VI has been created and documented for ease of use as a SubVI in a larger application.

Systinternals DU File Directory.png

ContextHelp_DU.png

George T.
Senior Applications Engineer
National Instruments UK and Ireland

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
BVSmith
Member
Member
on

This VI used to work, but now throws error 2.  I have tried hacking it with different forms of the command, but to no avail.

It needs to be updated so it works again.

I tried it with LabVIEW 2013 and 2015.

Brian Smith
Advanced Light Source
Lawrence Berkeley National Laboratory
Jabot
Member
Member
on

I've found that the issue with "Error 2" comes from the System Exec call. Placing DU or DU64 in the Windows\System32 location works well for calls directly from Windows but not from LabVIEW. I created a "Disk Usage" folder and moved DU64.exe to "C:\Program Files\Disk Usage" and the subject vi works quite well. Very happy to have this utility. Also, placing quotes around the path regardless of my OS; had some problem with Windows 10 and spaces within the filename.

 

Jeff Stutrud

Innovative Scientific Solutions Inc

Contributors