Sort file based on file prefix

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
6 posts Page 1 of 1

dchmax

Posts: 6
Joined: Tue Jun 10, 2014 1:23 pm

Post by dchmax » Thu Jun 12, 2014 2:33 pm
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.

Support_Jon

Support Specialist
Posts: 62
Joined: Thu Jul 19, 2012 9:15 am
Location: Ashland, NE

Post by Support_Jon » Thu Jun 12, 2014 3:17 pm
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.

dchmax

Posts: 6
Joined: Tue Jun 10, 2014 1:23 pm

Post by dchmax » Thu Jun 12, 2014 3:23 pm
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.

Support_Jon

Support Specialist
Posts: 62
Joined: Thu Jul 19, 2012 9:15 am
Location: Ashland, NE

Post by Support_Jon » Thu Jun 12, 2014 3:34 pm
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.

dchmax

Posts: 6
Joined: Tue Jun 10, 2014 1:23 pm

Post by dchmax » Mon Jun 16, 2014 10:59 am
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.

Support_Rick

Support Specialist
Posts: 590
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Tue Jun 17, 2014 8:52 am
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.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
6 posts Page 1 of 1