Altova FlowForce Server 2025 Advanced Edition

List Directory Contents

Home Prev Top Next

This tutorial shows how to configure a job that lists the contents of a directory and saves the directory listing as a TXT file. The broad outline is described below:

 

1.We will create a new job in the /public/Examples container.

2.After that, we will add an execution step that will run the shell command dir. This command lists the contents of the specified directory.

3.In the next step, we will add another execution step that will use the result of the first step and save this result as a TXT file called FileList.txt.

4.We will also configure a file-system trigger that will poll the directory for changes every 60 seconds and start the job whenever a new file is added to the specified directory.

5.We will also select an existing password credential, with which the job will be run.

6.After we have saved the job configuration, any existing files in the specified directory will be considered as newly created, and the job will be executed. As a result, FileList.txt will be created and will contain the directory listing.

 

Implementation

This subsection shows step-by-step instructions on how to create the job outlined above.

 

Step 1: Create a job

To create a job, follow the instruction below:

 

1.Log on to FlowForce Server.

2.Navigate to a container where you have the permission to create new jobs. For testing purposes, we will be using the /public/Examples container. If this container does not exist yet, create it using the Create | Create Container command.

3.In the /public/Examples container, create a new job by clicking Create | Create Job.

4.Enter a job name (e.g., SampleJob), and, optionally, a job description.

 

In our example, the job is called ListFiles and contains the following description: "Lists directory contents and saves the list as a TXT file."

 

Step 2: Add an execution step that lists directory contents

To add an execution step that lists the contents of a directory, follow the instructions below:

 

1.Click new Execution step in the Execution Steps section.

2.Type the name of the built-in function /system/shell/commandline in the Execute function field. This system function can execute shell commands and batch files.

3.In the Parameters | Command field, type dir. This command is used on various operating systems to list the contents of a directory.

4.The next step is to specify the working directory, whose contents will be listed. Click the plus icon so that the text field appears. In our example, the working directory is C:\Test\FlowForceServer\ExampleFiles.

5.To be able to use the result produced by this execution step, we need to assign the step's result to a value of the generic type result. In our example, the name of the value is list. You can select any convenient name for the step's result. For details about execution results, see Execution Result.

 

Step 3: Add an execution step that saves the directory listing to a file

To add an execution step that saves the directory listing to a file, take the steps below:

 

1.Add another execution step in the Execution Steps section.

2.Type the name of the built-in function /system/create-file in the Execute function field.

3.Type the name of the target file to which the directory listing will be saved. In our example, we will supply the full path to the target file: C:\Test\FlowForceServer\ExampleFiles\FileList.txt.

4.The next step is to supply the result of the first execution step in the Source Stream field. Since the result of the first step is of type result and the Source Stream field expects a stream, there is a mismatch between the data types. To be able to use the first step's result in the second step, the data types must match. Therefore, we will use the stdout expression function that takes result as its parameter and produces a stream. Type the following in the Source Stream field: stdout(list), where list is the name of the step result that we declared in Step 2.4 above.

5.Enable the Overwrite Target parameter - this will enable FlowForce Server to overwrite the files that already exist in the destination folder.

 

Step 4: Configure a file-system trigger that will fire the job

For any job you configure, you need to specify a condition or conditions that will start the job. In this tutorial, we will set a file-system trigger that will poll the directory we specified in Step 1 every 60 seconds. If new files are detected, the trigger will start the job and write the directory listing to the target file we specified in Step 3.3. To configure a file-system trigger, follow the steps below:

 

1.Navigate to the Triggers section and click New Filesystem Trigger. The trigger's block with various parameters appears.

2.Select Newly Created from the drop-down list of the Check parameter.

3.Supply the path to the directory that will be checked: C:\Test\FlowForceServer\ExampleFiles.

 

Step 5: Select a credential

When you create a job in FlowForce Server, you must supply the credentials of the user account with which the job must be executed.

 

In the Credentials section, we will select a password credential that we created before starting this tutorial. This is a standalone credential object that you can use in any job. Standalone credentials are convenient, because you can update them in one place when they change, and this change will affect all jobs that use that credential reference.

 

Alternatively, you can specify a local credential, by entering your user name and password.

 

For more information about types of credentials and instructions on how to create them, see Credentials.

 

Step 6: Save and run the job

To save the job configuration, click Save at the bottom of the configuration page. To run the job for the first time, we do not need to take any actions. When we add a new trigger and save the job configuration, any existing files in the specified directory will be considered as newly created, and the job will be executed.

 

To trigger the execution of the job again, we need to satisfy the trigger conditions, which means we need to add at least one file to C:\Test\FlowForceServer\ExampleFiles or rename an existing file in this directory.

 

Job outcome

After the job has successfully been executed, FileList.txt displays the directory's contents. An extract of this text file is shown below:

 

Directory of C:\Test\FlowForceServer\ExampleFiles

 

05/24/2024  02:18 PM    <DIR>          .

05/24/2024  02:18 PM    <DIR>          ..

05/23/2023  12:01 PM            25,126 Authors.xml

05/05/2023  05:17 PM             2,280 Authors.xsd

05/22/2024  11:05 AM               515 BookListBiography.json

05/22/2024  11:05 AM             1,560 BookListChildren.json

05/22/2024  11:06 AM             2,433 BookListClassics.json

05/22/2024  11:07 AM             2,447 BookListCrimeMystery.json

05/22/2024  11:08 AM             5,036 BookListFantasy.json

05/22/2024  11:08 AM             1,121 BookListHorror.json

05/22/2024  11:08 AM               477 BookListHumor.json

05/22/2024  11:09 AM               963 BookListSciFi.json

01/19/2024  07:22 PM             3,197 BookOrder.xml

12/06/2023  06:44 PM             1,663 BookOrder.xsd

09/11/2023  11:22 AM            17,905 Books.json

05/22/2024  11:02 AM               993 Books.schema.json

05/24/2024  02:18 PM             1,224 FileList.txt

05/24/2024  01:47 PM               368 Notes.txt

             16 File(s)         67,308 bytes

              2 Dir(s)  725,686,542,336 bytes free

 

Implementation shown in GIF

For a quick demo of the steps described in this tutorial, please click the GIF file below. Note that only Steps 2-4 and 6 are illustrated in the GIF. For an illustration of Steps 1 and 5, see the Hello World tutorial.

Click to play

 

© 2018-2024 Altova GmbH