Example Code

Count ALL Files in a Directory and Sub-directories Recursively Using LabVIEW

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

This VI will count ALL files in a specified folder and all sub-folders recursively.

 

Description

This VI makes use of recursion. A recursive VI must be reentrant (see LabVIEW help on reentrant). The VI creates a reference to itself and then calls Open VI Reference to open a new VI of itself. The new VI is passed with the subfolder of the parent folder and process is repeated for the subfolder (as if it were the parent folder).

Once all subfolders are traversed the sum of the subfolders count and the parent folders are added together to give a final count.

Beware of using this program on a large system directory. A new VI will be spawned fo reach subfolder in your folder tree and this could cause memory errors.

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Specify the folder path.
  2. Run the VI and check the VI numbers on the front panel indicator.

 

Additional Information or References

VI Snippet of Block Diagram

sni.png 

 

 **This document has been updated to meet the current required format for the NI Code Exchange. **

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