UDM - forfiles Statement - File Specification

UDM - forfiles Statement - File Specification

The file specification portion of the forfiles statement, file_spec, tells UDM how to build its list of files. It takes the same format as the copy command file specification and can contain wildcards.


To list all of the members in a PDS on a z/OS system, you can issue the following commands:

forfiles zos=MYHLQ.MYPDS(*)
  print msg=$(_file)
end


This would print the name of each member in a PDS called MYHLQ.MYPDS.


For Windows, UNIX, and IBM i systems (as well as the HFS file system under z/OS), you can list all of the files in the current directory with the following UDM commands:

forfiles local=*
  print msg=$(_file)
end



To find all of the files ending in .txt in a particular directory, mydir in this example, issue the following forfiles statement:

forfiles local=mydir/file?
  print msg=$(_file)
end



A question mark ( ? ) can be used as a wildcard for a single character. In the previous example, lets assume mydir contains the files: file, file1, file2, and file3.txt.

Executing the following:

forfiles local=mydir/file?
  print msg=$(_file)
end



Will result in the following output:

file1
file2


A Stonebranch Tip

The forfiles file specification can contain wildcards for any UDM files system.

Under z/OS, however, the wildcards only can be used to reference a member of a PDS or PDS/E.