How to scan a folder and report contents of files to email

Post any question you may have in regards to GoAnywhere MFT and let our talented support staff and other users assist you.
If you need a quicker response, please create a support ticket via the customer portal my.goanywhere.com or contact our support team by email at [email protected].
4 posts Page 1 of 1

ruttrowgeorge

Posts: 2
Joined: Thu Feb 22, 2018 6:35 am

Post by ruttrowgeorge » Wed Jul 29, 2020 8:28 am
My project has an error that I suspect is due to a variable being used incorrectly. I am trying to get output of files recursively in c:\temp. There are subfolders in there. Just want *.pdf. I want to put a list of the files in an email. Are there templates for this? My code below gives error "[8099 - Set Variable] An unexpected error occurred. Variable 'C:\TEMP\Chicken.pdf' is not a RowSet or an Array. Original expression: CurrFile[1]."
My code:
<project name="George" mainModule="Main" version="2.0" logLevel="verbose">

<module name="Main">

<createWorkspace version="1.0" />


<createFileList fileListVariable="data" version="1.0">
<fileset dir="C:\TEMP">
<wildcardFilter>
<include pattern="*.*" />
</wildcardFilter>
</fileset>
</createFileList>

<forEachLoop itemsVariable="${data}" currentItemVariable="CurrFile" disabled="false">

<setVariable name="myFile" value="${CurrFile[1]}" version="2.0" />


<print file="test.txt" append="true" version="1.0">
<![CDATA[${myFile}
]]>
</print>

</forEachLoop>

<sendEmail resourceId="fhcp" toList="[email protected]" keyLocation="KeyVault" version="2.0">
<from address="[email protected]" keyLocation="KeyVault" />
<subject>
<![CDATA[test]]>
</subject>
<message>
<![CDATA[${data}]]>
</message>
</sendEmail>


<deleteWorkspace version="1.0" />

</module>

</project>

Support_Mark

Posts: 3
Joined: Mon Feb 10, 2020 10:32 am

Post by Support_Mark » Fri Jul 31, 2020 5:25 pm
First, we will want to Create the File List

Image

Then, Print the File List to a reachable location, we will use this text file in the next step. Make sure to set Append to false so that you only send the most recent files.

Image

Finally, add the Send Email Task, hit Add to set the Message sub-task. With this method, you can set the File field to that text file that was just created. Add the rest of the information needed to send the email, and that's it!

Image

ruttrowgeorge

Posts: 2
Joined: Thu Feb 22, 2018 6:35 am

Post by ruttrowgeorge » Mon Aug 03, 2020 6:36 am
Thank you Mark.

Is there a way to do a carriage return after each file name? I got the code working you suggested but the output does not do a new line after each file found, unless it is in another subdirectory. That is, if two files are found in same directory, it outputs it on same line.

My code:--------------------------------------------------------------------------------------------------------------
<project name="test" mainModule="Main" version="2.0" logLevel="verbose">

<module name="Main">

<createWorkspace version="1.0" disabled="false" />

<createFileList fileListVariable="data" version="1.0">
<fileset dir="C:\Program Files\Linoma Software\GoAnywhere\userdata\webdocs" recursive="true" includeItems="files">
<wildcardFilter>
<include pattern="*.*" />
</wildcardFilter>
</fileset>
</createFileList>

<print file="C:\Program Files\Linoma Software\GoAnywhere\output.txt" append="false" version="1.0">
<![CDATA[From the job run at 8 pm tonight, these files were showing uploaded. If the below is blank no files were found.

${data}
]]>
</print>

<forEachLoop itemsVariable="${data}" currentItemVariable="CurrFile" disabled="true">
<setVariable name="myFile" value="${CurrFile[1]}" version="2.0" />

<print file="C:\Program Files\Linoma Software\GoAnywhere\output.txt" append="false" version="1.0">
<![CDATA[${myFile}
]]>
</print>
</forEachLoop>

<sendEmail resourceId="fhcp" toList="[email protected]" keyLocation="KeyVault" version="2.0">
<from address="[email protected]" keyLocation="KeyVault" />
<subject>
<![CDATA[test]]>
</subject>
<message file="C:\Program Files\Linoma Software\GoAnywhere\output.txt" />
</sendEmail>
<deleteWorkspace version="1.0" disabled="false" />

</module>

</project>

Support_Mark

Posts: 3
Joined: Mon Feb 10, 2020 10:32 am

Post by Support_Mark » Mon Aug 03, 2020 10:27 am
Hi George,

For this, we will have to read that text file back in and turn it into a Rowset. We can use a For-Each Loop and Print task to add a carriage return/line feed to the list.

Below, we have the same file list as last time, but now with Recursive set to true.

Image

Print out to that same text file with the same settings.

Image

Read the Flat File (text file) we just created and set the Record Delimiter to LF.

Image

On this step, we'll be Deleting the text file that we are going to Print to in the following task; this step just makes sure old data won't be present in our Email Message.

Image

Now, we use a For-Each Loop to examine each row of our Rowset that was created by reading in the text file containing our File List.

Image

And finally, we use another Print task with Append set to True in order to write out each row with a carriage return and line feed at the end of each line.

Image

Image

Now, we can use this text file as the Message for our Email task, and each file should receive it's own line regardless of the original folder it was in.
4 posts Page 1 of 1