Page 1 of 1

order of files in filelist

Posted: Tue Nov 05, 2013 1:52 pm
by monahanks
Hi, I have a GoAnywhere project that reads a folder and generates a Filelist variable. The files are named:
(folder path/)PPE 101913 - Week 37.xls and
(folder path/)PPE 102613 - Week 38.xls

When i generate the file list variable, it shows and processes the second (Week 38) file first. does the filelist function populate the list in reverse order (add files to top of stack), and if so is there a way to reverse that?

Re: order of files in filelist

Posted: Tue Nov 05, 2013 3:17 pm
by Support_Philip
Hello MonahHanks,
The createFileList task uses your operating system to read files in your folder and populate the variable. GoAnywhere Director does not currently have methods that allow you to sort the fileList, but you can create a forLoop and iterate through your fileList in reverse order. The forLoop would replace your forEachLoop and iterate using an index variable.

1. In your createFileList task, populate the Number of Files Found Variable field. In my example, I called the variable "numFiles." If your directory contains 8 files, then this variable will be assigned the integer 8.

2. Create a forLoop. On the Basic tab, use the ${numFiles} variable as the Begin Index. Set the End Index to '1', and set the Step to '- 1.'

On the Advanced tab, set the Current Index Variable to 'index.' The current file variable would now be ${fileList[index]}.

This loop will begin on Index 8 (the number or files in the directory) and decrement by 1 each time it loops, and end on the first file.

Here is an example of a forLoop that gets a list of files, and then prints them out in reverse order:
Code: Select all
<project name="File_List_Reverse_Order" mainModule="Main" version="2.0">

	<module name="Main">

		<createWorkspace version="1.0" />


		<createFileList fileListVariable="fileList" numFilesFoundVariable="numFiles" version="1.0">
			<fileset dir="C:\TestLoop" recursive="true" />
		</createFileList>

		<forLoop beginIndex="${numFiles}" endIndex="1" step="-1" currentIndexVariable="index">

			<print version="1.0">
				<![CDATA[${fileList[index]}]]>
			</print>

		</forLoop>
	</module>

</project>
Please let me know if you have any further questions.