Page 1 of 1

Sort file based on file prefix

Posted: Thu Jun 12, 2014 2:33 pm
by dchmax
I have x number of files that are being downloaded from an FTP server to the temp workspace. The prefix denotes which customer the file will need to be sent to. My plan was to sort the files by prefix into temporary folders with in the temp workspace. Once in their specific folder i need to remove the prefix before sending to customer.

ex. 001_B012R00962D20140602T2014060154044.txt

001_ being the prefix

Open to any suggestion to accomplishing the same result.

Re: Sort file based on file prefix

Posted: Thu Jun 12, 2014 3:17 pm
by Support_Jon
David,

If the order of the files when retrieved from the FTP server aren't in the order that you want, then some extra work will be needed to put them in the order you need. Currently, there is no built in way to sort a file list... but this functionality is on the road map for a future release of GoAnywhere Director. In the meantime you will have to follow this basic outline on how to pull it off.
  • create your file list
  • write the file list values to a temporary database(file name, full path)
  • retrieve the values from the temporary database (order by file name)
  • process the resulting rowset as needed.
Now in order to trim the prefix off of the file name as your are moving it to it's new destination, there are a few ways to accomplish this.

1) As you process each row, you can use the substring function against the file name to retrieve the file name without the prefix.

2) Alternatively, prior to processing rowset, you can use the Modify Rowset task (requires version 4.6.0 or later) to build an updated rowset that contains the existing values and an output file name exactly how you want them to be. Then from there, you can process the resulting output rowset.

Re: Sort file based on file prefix

Posted: Thu Jun 12, 2014 3:23 pm
by dchmax
Thanks for the reply.

In regards to the sort, I'm not sorting so the files are in a certain order. I'm sorting, moving, files into their respective temporary folder based on the prefix. Once in the folder I would remove the prefix and upload to customer. I was going to take the file list and loop through it.

Re: Sort file based on file prefix

Posted: Thu Jun 12, 2014 3:34 pm
by Support_Jon
dchmax wrote:
Thanks for the reply.

In regards to the sort, I'm not sorting so the files are in a certain order. I'm sorting, moving, files into their respective temporary folder based on the prefix. Once in the folder I would remove the prefix and upload to customer. I was going to take the file list and loop through it.
Ok. My details above still apply. when you do the move, you could specify the destination file name without the prefix... or you can move them, then when you rename the files, you can change the name at that point.

Either way you'll still have to loop through the list to accomplish what you want.

Re: Sort file based on file prefix

Posted: Mon Jun 16, 2014 10:59 am
by dchmax
My understanding is to rename the file I need to first assign the original name to a variable. I'm having difficulties getting this information from destination files variable. I've created a forEachLoop to go through the variable but I get the following error.

[9008 - rename ] Attribute 'newName' may only be specified when renaming a single file.

Maybe I'm going about it the wrong way.

Re: Sort file based on file prefix

Posted: Tue Jun 17, 2014 8:52 am
by Support_Rick
On the Rename Task, there are 2 options for the input file name... "Input File" & "Input Files Variable"

Then, there is only one "New Name"

If you have a single file (File Name), then typing the new name in the "New Name" field will work. If you're passing in an "Input Files Variable" (aka, multiple files) then you will need to give it a name in the "New Name" field, but you will also need to add a Prefix or Suffix (from the Advanced Tab) so that it gives each file name a unique value. By default, the Task does not rename multiple files to the same file name.

GoAnywhere automatically assumes that if you use the Input Files Variable, that there are multiple files. Whether there is just one or not.