Page 1 of 1

multiple extentions

Posted: Tue Feb 07, 2017 5:23 pm
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.

Re: multiple extentions

Posted: Tue Feb 07, 2017 11:42 pm
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.

Re: multiple extentions

Posted: Wed Feb 08, 2017 12:04 pm
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>

Re: multiple extentions

Posted: Wed Feb 08, 2017 1:58 pm
by Support_Rick
Try this:

<if condition="${ EndsWith( string( currentfile ), 'txt' ) }">

Re: multiple extentions

Posted: Thu Feb 09, 2017 11:43 am
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>

Re: multiple extentions

Posted: Thu Feb 09, 2017 12:46 pm
by Support_Rick
See the example above again ... you did not include the "string" function as stated. Please review, retry and let us know.

Re: multiple extentions

Posted: Thu Feb 09, 2017 12:57 pm
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>


Re: multiple extentions

Posted: Wed Feb 15, 2017 9:32 am
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" />