Two Stars

File Transfer

Hi,
I have a job to modify filenames of files(pdf) from source with static data inserted in the fourth component of file name such that it will have the following format
TAC_CAT_time/date_Op2_uniqueID.pdf. The filenames will already contain TAC_CAT_DATE_unique ID.pdf. thus Op2 (case sensitive) is missing. The TAC and CAT components are 8 and 9 characters long respectively. I have figured out all of the above, except that when the MRN or HAR are not within 8 or 9 characters long i need to generate a error. Sometimes these components are keyed in wrong by users. How do I filter these files? to generate a email.
So in effect the 28th character in my filename needs to "_".
22 REPLIES
One Star

Re: File Transfer

Hi
So in effect the 28th character in my filename needs to "_".

According to your requirement, we can create part of your job as follow.
Regards,
Pedro
Two Stars

Re: File Transfer

Hi Pedro,
Sorry its the 27th character, if you start from 0. So right now I have the following code in my tfilecopy component
---------------
((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(0,19)+((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(23,27)+((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(19,23)+"_"+"Op2"+"_"+((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(28,((String)globalMap.get("tForeach_1_CURRENT_VALUE")).length())
----------------
So should I be using tIterateflow instead of tforeach?. Will try as you suggested.
Thanks,
Two Stars

Re: File Transfer

Hi Pedro,
The job ran as you suggested. But in the destination folder I can see just one file that is transferred. The rest of the files are missing eventhough the job says it moved 11 files which is the correct number. I'm missing something here. Please help.
Thanks,
One Star

Re: File Transfer

Hi
From this image, we are sure that tFilerRow works fine.
It seems that there is something wrong in tFileCopy.
You'd better recheck it.
Regards,
Pedro
Two Stars

Re: File Transfer

Hi Pedro,
I just can't isolate the problem, Following are the screens when I use tlogrow and alternatively when I use tfilecopy
The destination filename code I have on Tfilecopy is as follows
----------------------------
((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(0,19)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(23,27)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(19,23)+"_"+"Op2"+"_"+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(32,((String)globalMap.get("tFileList_1_CURRENT_FILE")).length())
-------------------------------
When Tfilecopy is used with Tfilter will the files transfer or is Tfilter used to just list the filtered files but no physically move them?
Two Stars

Re: File Transfer

Sorry that is not the case. Its 5 parts before the insertion of "Op2" a constant. The destination files need to have 6 parts in total.
One Star

Re: File Transfer

I've got this routine for splitting strings into parts on a delimiter.
    /**
* reverseIt() Reverses a string.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} string ("fred") input: the string to be reversed
*
* {example} reverseIt("fred") # derf
*
*/
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--)
dest.append(source.charAt(i));
return dest.toString();
}
/**
* anyWord() finds a word in a string based on a delimiter and the number of the word required.
* It can search forwards or backwards depending on whether the number of the word is positive or negative.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} string("hello Example") input: The string need to be parsed.
*
* {param} string(" ") input: the delimiter
*
* {param} int(0) input: the number of the word to return - 0 is first occurrence -1 is the last.
*
* {example} anyWord("hello Example"," ",0) # hello
*/

@SuppressWarnings("finally")
public static String anyWord(String message, String delimiter, Integer number ) {
String returnString = null;
Integer reverseit = 0;
try {
if (number < 0) {
message = Ncl_routines.reverseIt(message);
number = -1 - number;
reverseit = 1;
}
if (delimiter.equals(" ")) {
String[] starwords = message.split (" ");
returnString = starwords;
}
if (! delimiter.equals(" ")) {
String[] starwords = message.split ("\\" + delimiter);
returnString = starwords;
}
if (reverseit == 1) {
returnString = Ncl_routines.reverseIt(returnString);
}
} catch (ArrayIndexOutOfBoundsException e) {
returnString = "";
} finally {
return returnString;
}
}
}

So for your string you could have
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",0) + "_" + anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",1) + "_" +
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",2) + "_" +
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",3) + "_" +
"Op2_" +
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",4)

This saves worying about the length of each component.
"
Two Stars

Re: File Transfer

Ok the third component is a date which is in mmddyyyy, I need it in yyyymmdd. So how do i deal with that?. I am currently using the following in the 3rd component.
-----------
((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(23,27)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(19,23)
-----------
Could I use the one above in the 3rd part of your code ?
One Star

Re: File Transfer

Do the substring on the anyWord.
Two Stars

Re: File Transfer

The problems still persists. There is just one file each ( one from the filter and other from reject) moved to the destination folders. Why is this?. I have no clue why just one file is moved to the destination although the job says otherwise.
One Star

Re: File Transfer

What are the input and output file names for your file copy?
Your tFilterRow should use .equals not ==
Two Stars

Re: File Transfer

For tfilecopy1:
Filename is : ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))
Destiantion Filename : ((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(0,19)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(23,27)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(19,23)+"_"+"Op2"+"_"+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(32,((String)globalMap.get("tFileList_1_CURRENT_FILE")).length())
--------------------------------------------------------------------------
For tfilecopy 3: Filename is : ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))
Destiantion : Local drive.

I know you suggested using routines but I haven't. Still there is no explanation to why just a single file gets moved but not the rest
One Star

Re: File Transfer

You need to use the file name from tFilterRow for the output file name. The one from tFileList will always be the same as it's before the iterate.
Two Stars

Re: File Transfer

you mean in Rename - destination fielname?
One Star

Re: File Transfer

Sorry I'm talking rubbish - tFileList file name is after the iteration.
What does the tLogRow show for the file name in your earlier example?
Two Stars

Re: File Transfer

Ok, the tlogrows shows the rejects and filtered files according to the condition specified in tfilterrows. I have merely replace the tlogrows with tfilecopy in the earlier example.
Two Stars

Re: File Transfer

When I hit ctrl+space in Tfilecopy destination rename should I be choosing
"((Integer)globalMap.get("tFilterRow_3_NB_LINE_OK"))"... but what is the Integer part?.
One Star

Re: File Transfer

OK I think the input file name is in the column name that comes out of tFilterRow - that's why it's displayed in tLogRow.
Does the file that's being created look like any of the names you're expecting?
Two Stars

Re: File Transfer

yes in the tfilecopy( good files) i see one file with the modifications I have specified. Similarly in tfilecopy(reject files), I see one file that is not according to specifications. So of the 20 rows processed 9 are bad and 11 good. Problem: I see just one of each category in their respective destinations.
One Star

Re: File Transfer

Hi
I have received your email.
Let's say the specified source directory is "E:/TOS_DI-r75219-V5.0.1NB/workspace/".
You can set source filename of tFileCopy as the following images.
Use row2.columnname to define destination name instead of tFileList_1_CURRENT_FILE.
Regards,
Pedro
Two Stars

Re: File Transfer

Thanks Pedro. The job works now.
I left the tfilecopy source name to tfilelist_current_filepath and altered the destination rename to "row2.filename".
One Star

Re: File Transfer

Long Path Tool helped me in this situation. http://PathTooDeep.com Smiley Happy