Example Code

List the Sizes of All Files on Disk and Write to Spreadsheet

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

Coding that exemplifies how to list the size of all files within a selected folder and store the information into a spreadsheet file.

 

Description
This VI uses the Recursive File List VI to obtain all files in a directory, even files in directories within the main directory. The VI then lists the size file of each, and writes this information to a spreadsheet file that can be opened in Excel or Notepad.

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code
1. Select the folder that you would like to analyze.
2. Select the spreadsheet file that will held the information.
3. Run the VI.

 

Additional Information or ReferencesSnippet.png

Product Support Engineer
National Instruments

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

Comments
gt3000
NI Employee (retired)
on

This VI is useful.  To make the Front Panel more practical, both the File Path Controls can be changed to allow the user to select a Folder, rather than just a file.

  1. Right-click on the 'Folder Path' file path control and select 'Browse Options'.
  2. In the category 'Selection Mode', select 'Files and Folders' and click 'OK'.

Now when the user browses, they have the option to select 'Current Folder' when in a folder.

On OS's like Vista and Windows 7, the user will receive an error when trying to save a file to the C:\ drive.  In order to allow a user to choose a new file name at a new location on the PC, the following changes must be made.

  1. Right-click on the 'Save to Path' file path control and select 'Browse Options'.
  2. In the category 'Selection Mode', select New or Existing' and click 'OK'.

Now when the user browses, they have the option to to create a new file in 'My Documents' or the 'Desktop' with a file name of their choosing.

George T.
Senior Applications Engineer
National Instruments UK and Ireland