UDM - forfiles Statement - Built-In Variables

forfiles Statement - Built-In Variables

The forfiles statement provides the following built-in variables: _filecount, _file, and _path.

_filecount contains the number of files that match the forfiles statement file specification. This value also represents the number of iterations that you can expect UDM to execute for the forfiles statement. UDM stores the name and absolute path of the file being processed by the current iteration in the _file and _path variables.

For example, assume the following:

  • UDM has opened a session with a remote Windows machine and assigned it a logical name of win.
  • A directory exists on win named C:\Example.
  • Three files - file1.txt, file2.txt, and file3.txt - reside in C:\Example.


The following script segment prints the file name and absolute path of each file in the directory:

forfiles nt=C:\Example\*
    echo "Filename: $(_file) Abs. Path: $(_path)"
end
echo "Number of files processed: " $(_filecount)


Executing this would build a file list containing the files: file1.txt, file2.txt, and file3.txt. Since there are three files in the list that was built, UDM would iterate through the loop three times:

  1. During the first iteration through the loop, the _file variable would contain file1.txt and the _path variable would contain C:\Example\file1.txt.
  2. During the second iteration, the _file variable would contain file2.txt and the _path variable would contain C:\Example\file2.txt.
  3. During the third and final iteration, the _file variable would contain file3.txt and the _path variable would contain C:\Example\file3.txt.
  4. For each iteration of the loop, _filecount remains constant and contains the number of files that were added to the file list by the forfiles statement. UDM preserves the value of _filecount after the forfiles statement completes.


This script segment would result in the following output:

Filename: file1.txt Abs. Path: C:\Example\file1.txt
Filename: file2.txt Abs. Path: C:\Example\file2.txt
Filename: file3.txt Abs. Path: C:\Example\file3.txt

Number of files processed: 3



_file Variable Attributes

The _file variable also has special attributes that further define a file.

For efficiency reasons, all of these attributes - other than name and type - are retrieved only as requested. You can request to retrieve the file attributes by adding fileattrib=yes to the end of the forfiles call.

For example:

forfiles src=*.txt fileattrib=yes
    echo "$(_file) is $(_file.size) bytes in size."
end



If the information for an attribute cannot be obtained, its value is set to an empty string.


z/OS

z/OS datasets store only createdate and accessdate. There is no time (createtime and accesstime) associated with these dates, nor do z/OS datasets store moddate or modtime.