Problem:I want to move files containing a specific keyword to a specific folder
To start with we need to define 3 things:
1. They keyword we are searching for,
2. The folder whose files we shall be looking into
3. The folder to which the files should be moved to in the event the keyword is found within.
It is very important that we understand that the "Read Text from File" action, can only be used to read the contents of files that can be successfully read within notepad.
So we use a "Display Input Dialog" action to allow the user define the keyword, we use a "Display Select Folder" dialog to select the folder we shall be looking within for files that contain the keyword we are looking for, and a second "Display Select Folder" dialog to select the folder to which we shall be moving our files.
Having done that, we can now configure our job to get a list of the files contained within the folder we selected, using the variable name that holds the selected folder in the "Get Files in Folder" action Folder field. We also define the types of files we want to search against (e.g. *.txt;*.xml;*.html, etc). As previously mentioned, the file types we can check against can only be files that can be opened with a notepad editor and still make sense!
Having done that, we create a new variable to hold the number of files being moved during the run process. We set this variable to 0, to start with, and during run it will either increase if a file is moved or if the action is not moved, it will remain 0.
Using a "For each" loop action, we loop through each file in the folder, and for each file we then use a "Read text from file" action and read its contents. Using an "If" condition action, we check if the contents contain the keyword we are looking for.
In the event that the keyword is found, we then want to move the current file to the folder we previously defined. That can be done using a "Move File(s)" action, where we define we want to move the current file, to the Folder we previously selected for all items to be moved.
Having done that, since we also want to keep a history of all files being moved, we also append the current file's full path to the text file on our desktop. If the job is running for the first time, it will simply create that file, if the job has run before it will simply use the existing file to append the information to.
And last, we need to increase the variable that holds the count for the files that have been moved. So we use the "Increase Variable" action to increase the count number.
Since the job has completed, we want to display the number of files that were moved during this run. This we achieve using a "Display Message" action that will display the number of files that were used