LoginSignup
0
0

【Scheduler】Creating a task accessing file system

Posted at

I'm planning to try using the Sharperlight Scheduler to perform actions such as copying files and exporting file lists to a file.

The folder structure, as shown in the diagram below will be used.
image.png
Each folder contains files like the ones shown below.
image.png
I'm planning to access these folders and files from the scheduler task.

Folder Security

Normally, Sharperlight is installed and operated on the application server. Allowing unrestricted access to the application server's folders poses a security risk. Therefore, Sharperlight provides the ability to register folders allowed for access using site setup. Let's proceed with the configuration.
Launch the Site Setup from the Sharperlight application menu.
Select Product Settings and System from the tree view.
The options for product settings will be displayed on the right side. In the bottom option, Secure Folders, specify the path of the folder you want to access in this case. If there are multiple folders, concatenate them with the pipe symbol (|).
image.png
Close the Site Setup dialog by clicking the Close button.
Restart the Sharperlight service to apply the changes.

Creating a Scheduler Task

Launch the Scheduler from the Sharperlight application menu.
image.png
Initiate the task creation by clicking the New button.
image.png
In the General tab, enter the Code, Group and Description.
image.png
Navigate to the Action tab and define the process you want to execute here.

Exporting a list of files to CSV

This time, I will check all the subfolders under C:\QiitaSampleTemp\ and create a CSV file listing all the files. At the same time, I will copy all the files to the C:\QiitaSampleCopy\ folder.
Add a new action by clicking the New icon.
Select Query Combinations from the list of available actions.
image.png

Configure the settings for Query Combinations. This action functions like a for loop.
By defining the query here, you can pass a row one by one from the dataset returned by the query to the next action.
Let's begin creating the query by clicking the Edit Query button.
image.png
The familiar Query Builder will open. Select Summary Report as the Mode, and choose System as the Product.
image.png
Select File List for the Table in the query
image.png

Folder will be displayed as a mandatory filter. Choose the folder you want to access.
image.png
To ensure access to sub folders, confirm that the Sub Folders is set to Y as another mandatory filter.
image.png
Next, specify the following items in the output area from the selection list.
image.png
Try the query by clicking the Preview button.
image.png

The file list will be returned. Exclude the first row from the query as it is unnecessary. Return to the query definition by clicking the Back to Query button.
image.png
Drag and drop Size from the selection list to the filter area. Set the condition to Greater than 0.
image.png
Try the query again by clicking the Preview button. The unnecessary first row should now be excluded.
image.png
Furthermore, in this query, keep only the following output items and remove the others.
image.png
Executing the query will return a dataset similar to this.
image.png

With this, the query is complete. Values will be passed one by one from this dataset to the next action as parameters. Click OK to save the query and return to the Action tab.
Add a new action by clicking the New icon.
The Query Combinations action, which was defined earlier, requires a corresponding Query Combinations End action to terminate the loop. Add this action first.
image.png
image.png
Now, let's define the core action that processes each row of the dataset obtained by the Query Combinations action. Add a new action using the New icon. This time, use the Query action. This action will be defined between the Query Combinations and Query Combinations End actions.
image.png
Define the query by clicking the Edit Query button.
image.png
The query filters will be the same as before.
image.png
However, this time, we will pass the folder name obtained by the Query Combinations action to the Folder filter. Use the unique reference name displayed at the right end of the Folder filter, which is @Folder.
image.png
Before that, set the following items in the output area from the selection list.
image.png
Save the query by clicking the OK button.
In the Query Parameters, enter Folder=. This represents the reference name of the Folder filter in this query. It means passing a value to the Folder filter in this query.
image.png
The value to pass is the folder name obtained by the previous Query Combinations action, so use the reference button on the right to search and set it.
image.png
Complete the settings by clicking the OK button.
image.png
Next, write the results of this query to a CSV file. The settings for this are on the right side.
image.png
The settings will be as follows. The Append checkbox means appending data to the same file.
image.png

File Copy

Add the File Copy action.
image.png
Set the source and destination of the file as follows. Utilize the return value of the previous Query Combinations action.
image.png

With this, the definition of the core actions are also completed.
Save the task by clicking the OK button.
image.png

Validation of the Scheduler Task

Select Execute from the right-click menu.
image.png
If no errors or issues are displayed, everything is working correctly.
Let's quickly locate the created file list, FileList.csv.
Great, it's there.
image.png

Let's also check the C:QiitaSampleCopy folder. You can see that the files have been copied.
image.png

Afterword

This time, I used the Sharperlight scheduler to create a list of files and tried copying files. While this isn't a task typically done using scheduling, I wanted to convey that such usage is possible among the numerous features available. Thank you and goodbye.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0