I have a method that scans a directory and copies each file found to a sub-directory ("backup"). The problem is that the directory scan routine ("CBL_DIR_SCAN_READ") does not return with a file name. I get all of the time stamp info for a valid file, but no name. Could you tell me what I am doing wrong. Here is my method:

       Working-Storage Section.
       01 ScanHandle         Pointer.
       01 ScanPattern.
           05 Patternlength  Pic XX comp-5       Value 3.
           05 PatternText    Pic XXX             Value "*.*".
       01 ScanAttrib         Pic X(4) Comp-5     Value 1.     
       01 ScanFlags          Pic X(4) Comp-5     Value 2.
       01 changeStatus       Pic XX Comp-5.
       01 ScanStatus         Pic XX Comp-5.
       01 CopyStatus         Pic XX Comp-5.
       01 ScanEntry.
           05 EntryAttrib    Pic X(4) Comp-5.
           05 EntryDateStamp.
               10 Year       Pic X(4) Comp-5.
               10 Month      Pic XX   Comp-5.
               10 DOW        Pic XX   Comp-5.
               10 Hour       Pic XX   Comp-5.
               10 Minute     Pic XX   Comp-5.
               10 Seconds    Pic XX   Comp-5.
               10 Mill       Pic XX   Comp-5.
               10 DST        Pic X    Comp-5.
               10 FileSize   Pic X(8) Comp-5.
               10 FileName.
                  15 NameLn Pic XX    Comp-5.
                  15 NameTx.
                       20 NT Pic X Occurs 1 to 256 Times Depending on NameLn.
       01 FileName1          Pic X(256).
       01 fileName2          Pic X(256).
       01 filePath           Pic X(256).                     
       procedure division using by value sender as object e as type System.EventArgs.
           Set FilePath to LB_Path.
           Call "CBL_CHANGE_DIR" Using FilePath Returning ChangeStatus.
           If ChangeStatus Not = Zeroes Exit Method.
           Call "CBL_DIR_SCAN_START" using by Reference Scanhandle,
                                           By reference ScanPattern,
                                           by Value ScanAttrib,
                                           By Value ScanFlags,
                                           Returning ScanStatus.
           If Scanstatus Not = Zeroes Exit Method.                                          
           Call "CBL_DIR_SCAN-READ" using By Reference ScanHandle,
                                          By Reference ScanEntry,
                                          Returning ScanStatus.
           If ScanStatus = 0
               Set FileName1 to LB_Path & "/" & NameTx
               Set fileName2 to LB_Path & "/backup/" & Nametx
               Call "CBL_COPY_FILE" using FileName1, FileName2, Returning CopyStatus
               If CopyStatus Not = Zeroes
                   Invoke type MessageBox::Show("Copy Error: Code=" & CopyStatus, "Copy Error",
                                                type MessageBoxButtons::OK,
                                                type MessageBoxIcon::Error)
      *            Exit method
           If ScanStatus = 0 go to Loop.                                                    

  • Verified Answer

    When testing your method I get an error on the cbl_dir_scan_read for index overflow because you have the filename field defined with an ODO but you do not set the value of NameLn prior to the call:

                10 FileName.

                     15 NameLn Pic XX    Comp-5.

                     15 NameTx.

                          20 NT Pic X Occurs 1 to 256 Times Depending on NameLn.

    If I add the following statement before the call it works fine

    move 256 to NameLn

    You are using a field named LB_Path which is not shown in your example so I just used one defined as:

    01 lb_path  pic x(256) value "C:\TEMP".

    And when I do the call it returns the names of the files in c:\temp just fine.

    BTW, you have a hyphen in the name of the routine where it should be an underscore but the compiler translates this anyway...

       Call "CBL_DIR_SCAN-READ"


  • Verified Answer

    Hi Jerry,

    try the following to Keep things in line - to Keep unneeded Points out of the code.

         * set ScanEntry start values

              initialize ScanEntry

              set NameLn to 256


              Set FilePath to  LB_Path

         * get length of path    

              perform varying cnt from length of LB_Path by -1 until LB_Path(cnt:1) not = space or cnt = 0


         * set search criteria    

              set Patternlength to 3

              set PatternText to "*.*"

         * change to directory      

              Call "CBL_CHANGE_DIR" Using FilePath Returning ChangeStatus

              If ChangeStatus Not = Zeroes goback end-if

              Call "CBL_DIR_SCAN_START" using by Reference Scanhandle


                                              by Value ScanAttrib


                                              Returning ScanStatus

              If ScanStatus Not = Zeroes



              perform with test before until ScanStatus not = 0

                  Call "CBL_DIR_SCAN_READ" using By Reference ScanHandle

                                                 By Reference ScanEntry

                                                 Returning ScanStatus

                  If ScanStatus = 0

                      Set FileName1 to LB_Path(1:cnt) & "\" & NameTx

         * create Backup path

                      Set fileName2 to LB_Path(1:cnt) & "\backup"

                      call "CBL_CREATE_DIR" using fileName2

                                              returning return-code


                      Set fileName2 to LB_Path(1:cnt) & "\backup\" & Nametx

                      Call "CBL_COPY_FILE" using FileName1, FileName2, Returning CopyStatus

                      If CopyStatus Not = Zeroes

                          Invoke type MessageBox::Show("Copy Error: Code=" & CopyStatus, "Copy Error",

                                                       type MessageBoxButtons::OK,

                                                       type MessageBoxIcon::Error)

         *                Exit method




          end method.

  • I would Like to thank both of you for your suggestions. I thought that the File Name and Name Length were return values. There is a lot of info that is either missing of confusing in the docs. It would be useful if small examples would accompany the routine calls.

  • I do agree that a sample in the docs would be nice for all of these calls.

    I would just like to point out that the parameters to these library routines are clearly marked as either On Entry or On Exit where On Entry specifies the parameters that need to be set before the call.

    For cbl_dir_scan_read it has:

    On Entry:


    Set by CBL_DIR_SCAN_START. This field identifies the search operation. Search parameters cannot be changed for a given handle.


    The length of the entry-name field.

  • I agree that the documentation for this area would be enhanced by a sample. I will see if this is something that we can provide in a future release.