HP OpenVMS Systems

ask the wizard
Content starts here

DCL and counting files?

» close window

The Question is:

I have a series of directories that I need to collect the number of files in
 the directories.  I cannot exceed 100 files in each directory.  Therefore, I
 need to know how I can pipe the report of the files in each directory into
 variables.  I can then gen
erate a report from the variables.  Maybe this is not the best approach.
 Nevertheless, I need to automate this task for monitoring.  Any suggestions?

The Answer is :

  From your description, the OpenVMS Wizard will assume you want some
  DCL code which will count the number of files in a particular directory
  and write the result into a DCL symbol.
  Symbols are problematical with the PIPE command as each component in
  the pipeline executes in its own subprocess. Since subprocesses do not
  share symbol tables, there is no way to define a symbol across
  processes.  (Please see the OpenVMS FAQ for details.)
  A simple and supported, but, for large directories, potentially slow
  method to solve this problem is to count the files using F$SEARCH.
  For example:
    $ IF p1.EQS."" THEN INQUIRE p1 "Directory"
    $ count=0
    $ loop: IF F$SEARCH("''p1'*.*;*").EQS."" THEN GOTO EndLoop
    $   count=count+1
    $   GOTO loop
    $ EndLoop:
    $ SHOW SYMBOL count
    $ EXIT
    $ @dircount DKA100:[WIZARD]
      COUNT = 1028   Hex = 00000404  Octal = 00000002004
  If you really want to use PIPE, the following two commands might do,
  but note that it is necessary to use the job logical name table to
  return the value to the parent process. Also note that the spaces
  around the ";" characters are required.
           SEARCH SYS$INPUT "Total of " | -
           ( READ SYS$INPUT LINE ; -
             COUNT=F$ELEMENT(2," ",LINE) ; -
  It's entirely possible that for directories with only 100 files, the
  former code would be quicker than the latter.  Please also note that
  parsing the output of the DIRECTORY command is not supported, and this
  SEARCH sequence may or may not function as expected in future OpenVMS

answer written or last revised on ( 3-JUL-2000 )

» close window