Parse directory listing example

This example gets a directory listing from and FTP directory using the FTP List Files activity, parses the long directory listing using Flat File Scheme, iterates through the list of files, based on the properties of each file.

About this task

Based on the properties of each file, one of the following actions occurs:

To open, view, and learn more about the FTPParseDirListingExample:

Procedure

  1. Extract the FTPParseDirListingExample project:
    1. Find the Default Create Path defined in Studio, the directory that new projects are created in. To view the current Default Create Path, select File > Preferences... from the Studio toolbar menu. The Preferences window is displayed. The current Default Create Path displays at the end of the pane. By default, the Default Create Path is located in the following directory: C:\Documents and Settings\ myLogin\My Documents Where myLogin represents your Windows login name.
    2. Find the FTPParseDirListingExample.zip file that contains the files that make up the FTPParseDirListingExample project. If you accepted the defaults during the installation of Studio, this file is located in the following directory: C:\Program Files\IBM\WebSphere Cast Iron Studio 3.X\Samples\FTPParseDirListing
    3. Copy the FTPParseDirListingExample.zip file from the FTPParseDirListing directory to the Default Create Path directory.
    4. Extract the contents of FTPParseDirListingExample.zip file into the Default Create Path directory.
  2. Open the FTPParseDirListingExample project:
    1. Select File > Open Project... from the Studio toolbar menu. The Open dialog box is displayed.
    2. Browse for and open the FTPParseDirListingExample directory.
    3. Click on the FTPParseDirListingExample.sp3 file and click Open. The project is displayed.
  3. In the Project tab, double-click the processBids orchestration. The processBids orchestration tab displays the activities of the orchestration, as shown in the following figure:
  4. Click the Schedule Job activity. Click the Configure task in the Checklist. During run time, this activity starts an orchestration job every 5 minutes.
  5. Click the FTP List Files activity labeled List Files Full Dir Listing. Click the Configure task in the Checklist.. This activity gets a long directory listing of the files in the /input directory on the FTP Server and returns the listing as one string in the dirListing output parameter. In this example, the string returned in the directoryListing output parameter is stored in the fullDirectoryListing string variable.

    If the FTP Endpoint has been configured for the Parse Directory Listing Example, click Test in the Configure task to get the directory listing. The List Only Files (NLST) check box determines if the directory listing contains just the list of files or a full directory listing. For this example, clear the List Only Files (NLST) check box.

  6. Expand the If...Then activity. During run time, this activity checks the value of the fullDirectoryListing string variable and if the value is empty, the If path is run and the orchestration ends. If the fullDirectoryListing string is not empty, the Else path is run and the orchestration parses the directory.
  7. Click the Read Flat File activity. Click the Map Inputs task in the Checklist. During run time, the long directory listing created in the FTP List Files activity, is passed to the Read Flat File activity via the Data input parameter.
  8. Click the Map Outputs task in the Checklist. During run time, the Read Flat File activity parses the directory string into the repeating node structure displayed in the Map Outputs task.

  9. Click the For Each activity. During run time, the For Each activity iterates through the repeating node structure that stores the directory listing. Each iteration is equivalent to a singe file and the properties of that file.

  10. Click the Map Variables activity. During run time, the Map Variables activity converts the size of the current file into a decimal number.

  11. Click on the If..Then activity. During run time, the If..Then activity starts the following If..Then branches.

Results

  • If the size of the file is equal to 0, the FTP Rename File activity moves the file to the /processFailed directory and renames the file by adding the ERROR prefix to the file name.
  • If the file name contains a string representing one of the approved supplies (AcmeInc or  WidgetRUs), the FTP Rename File activity based on the file name, moves the file to the appropriate directory either /processAcmeInc or /processWidgetRUs.
  • If the file name contains the string representing the Budget Manufacture supplier, the FTP Delete File activity removes the file because Budget Manufacture is on the unapproved supplier list.
  • If the file is not processed by any of the three previous conditions, the Else clause is called and the FTP Rename File activity moves the file to the /processNewCompany directory.

To run the Parse Directory Listing Example, see the procedures provided in the Configuring the FTP Endpoint for the Parse Directory Listing Example section.




Feedback | Notices


Timestamp icon Last updated: Wednesday, 15 June 2016


http://pic.dhe.ibm.com/infocenter/wci/v7r0m0/topic/com.ibm.wci.doc/Parse_Directory_Listing_Example.html