Skip to content

multiple extentions

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].
  • ehersh Offline
  • Posts: 56
  • Joined: Mon Sep 26, 2016 12:50 pm

multiple extentions

Post by ehersh »

We have some customers that sends us files that are like filename.txt.txt. We even had one that had 3 .txt on it. The iussue is sometimes when we get that ands load it it escapes our duplicate file check and gets processed with the same records it had before. Is what we are looking at is potentially dropping all TXT's on a file and then slapping just one .txt on it. We cannot do this by looking for the he4 first dot because some file names have dots in it I.E. file.name.txt. We cannot use name without extention because it will drop only the last .txt which will not work if the file has 3 .txt's on it. There are 2 potential possibilities that I can think of.
1. if there is more than 1 .txt cut it down to 1 .txt
2. Drop all .txt's and then just slap one on it.

Any suggestions on the easiest way to do this.
  • Support_Rick Offline
  • Support Specialist
  • Posts: 590
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Re: multiple extentions

Post by Support_Rick »

Just loop through the file name looking for the file name "endswith" ".txt"

Just do that until the file does not end with ".txt", then add one and finish.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
  • ehersh Offline
  • Posts: 56
  • Joined: Mon Sep 26, 2016 12:50 pm

Re: multiple extentions

Post by ehersh »

we tried that and got the following error:

Job failed. Job number is '1397289874174'.
[8099 - get file] An unexpected error occurred. Function 'EndsWith': Parameter '1' must be a string value. Function definition: 'EndsWith(haystack, needle[, caseSensitive]) returns boolean'
[/quote]

This is the code we are using:

Code: Select all

<doWhileLoop condition="${Contains(currentfile,&apos;.txt&apos;)}" disabled="false">
				<if condition="${EndsWith(currentfile,&apos;txt&apos;)}">

					<rename inputFilesVariable="${currentfile}" searchPattern="${currentfile}" replaceWith="${currentfile:nameWithoutExtension}" outputFilesVariable="renamefile" version="1.0">
						<fileset dir="<path to>/Inbound" />
					</rename>

				</if>
			</doWhileLoop>
  • Support_Rick Offline
  • Support Specialist
  • Posts: 590
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Re: multiple extentions

Post by Support_Rick »

Try this:

<if condition="${ EndsWith( string( currentfile ), 'txt' ) }">
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
  • ehersh Offline
  • Posts: 56
  • Joined: Mon Sep 26, 2016 12:50 pm

Re: multiple extentions

Post by ehersh »

I am now getting the following error


Project 'Project Name' failed. Job number is '1397289878761'.
[8099 - Rename] An unexpected error occurred. Function 'Contains': Parameter '1' must be a string value. Function definition: 'Contains(haystack, needle[, caseSensitive]) returns boolean'

In this code

Code: Select all

					<rename searchPattern="${ Contains( currentfile, txt ) }" replaceWith="${currentfile:nameWithoutExtension}" outputFilesVariable="renamefile" version="1.0">
						<fileset dir="<path to>/Inbound" />
					</rename>
  • Support_Rick Offline
  • Support Specialist
  • Posts: 590
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Re: multiple extentions

Post by Support_Rick »

See the example above again ... you did not include the "string" function as stated. Please review, retry and let us know.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
  • ehersh Offline
  • Posts: 56
  • Joined: Mon Sep 26, 2016 12:50 pm

Re: multiple extentions

Post by ehersh »

Project 'Project Name' failed. Job number is '1397289878959'.
[8099 - Rename] An unexpected error occurred. Function 'Contains': Parameter '1' must be a string value. Function definition: 'Contains(haystack, needle[, caseSensitive]) returns boolean'

Code: Select all

	<rename searchPattern="${EndsWith(String(currentfile), &apos;txt&apos; ) }" replaceWith="${currentfile:nameWithoutExtension}" outputFilesVariable="renamefile" version="1.0">
						<fileset dir="<path to>/Inbound" />
					</rename>

  • ehersh Offline
  • Posts: 56
  • Joined: Mon Sep 26, 2016 12:50 pm

Re: multiple extentions

Post by ehersh »

It has tested successfully, thank you for your help. In case anyone else needs to do something similar I included the code.

Code: Select all

<forEachLoop itemsVariable="${get_file}" currentItemVariable="currentfile">

			<setVariable label="Get file name" name="filename" value="${currentfile:name}" version="2.0" />

			<if label="IF file has .txt" condition="${EndsWith(String(filename), &apos;.txt&apos;)}">

				<setVariable label="get position" name="position" value="${PositionOf(filename, &apos;.txt&apos;)}" version="2.0" disabled="false" />


				<setVariable label="renamed file" name="testname" value="${Substring(filename, 1, position-1)}" version="2.0" disabled="false" />


				<rename inputFile="${currentfile}" newName="${testname}" version="1.0" />
Post Reply