Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Copy to directory - match left 5 characters

Hi

I have to copy (tFileCopy) files to directories but I only know the 5 first characters of directories names.

context.path_10000 + "/" + (globalMap.get("no_bon_commande")

My "no_bon_commande" is like "22345" and directory name can be "22345 - General folder for XXXX")

What do I have to add to copy to the final directory? I tried left ("no_bon_commande),5), etc.... without succes

Thank you

Martin

Labels (2)
8 Replies
Anonymous
Not applicable
Author

Hi Martin,
I have a solution to your problem. Since I am not good in Java  0683p000009MAB6.png, I have implemented the solution to your problem using windows batch scripting and Talend.
The overall process is as follows:
[list=1]
  • Write a bat script or respective commands in tSystem component where we will find the folder starting with 5 wild card characters as per your problem statement. Copy the output in a txt file (code this part in the same batch script). 

  • Now, read this file (On subjob OK), pull only line 4 (tSampleRow) as the folder name for which we are interested will be present at this line always, find the folder name using tMap string handling functions as explained below which will give us the exact folder name and copy the output to a context variable using tContextLoad.

  • Finally, use tFileCopy to copy your file and in the destination parameter, concat the path with the context variable which we loaded in step #2.


  • Batch script:
    😧
    cd <Path to the parent directory in which we have our sub directories from which we need to select proper directory for dumping our file by using only first 5 letters>
    dir abcde* /s /p > <path and file name of the file where we want to write the output of this batch script>

    Here, 😧 is the directory which contains sub folders where I want to copy my files.
    abcdefg is the directory where I want to copy my file and so I have only written abcde* in the code as per your problem statement.

    tMap expression for step #2:

    StringHandling.EREPLACE(StringHandling.EREPLACE(row11.Col1," ","") ,StringHandling.LEFT(StringHandling.EREPLACE(row11.Col1," ","") ,StringHandling.INDEX(StringHandling.EREPLACE(row11.Col1," ",""),">")+1 ),"")

    col1 is the output column from tSamleRow. 
    You will see value for this field as 19-12-1601:50PM<DIR>abcdefg where abcdefg is the folder where I need to copy my file.
    Here, I am first removing all the blank spaces, followed by eliminating all the unwanted characters to fetch the desired folder name (abcdefg).
     
    Attached is the Job screenshot for your reference.

    I know this is not a complete dynamic solution but at least this will give you some idea from where you can proceed.
    0683p000009MG7n.png
    TRF
    Champion II
    Champion II

    Hi,
    You may also use tFileList to get complete folder name then you can use tFileCopy.
    Is it clear for you?
    Regards,
    TRF
    Anonymous
    Not applicable
    Author

    I tried using tFileList but I was unable to fetch exact folder name using wild card search.
    Could you please elaborate?

    Thanks,
    Zaki.
    Anonymous
    Not applicable
    Author

    Hi

    I also try to fetch folders name with tFileList

    context.chemin_10000 + "/" + LEFT(globalMap.get("tFileList_4"),5)

    without succes.

    By the way, this way will not help me to match with my "no_bon_commande" var

    Martin
    TRF
    Champion II
    Champion II

    Did you try this?
    0683p000009MG7s.png
    Regards,
    TRF
    Anonymous
    Not applicable
    Author

    Hi

    You have two tFileList in your example:1 and 4
    What do you do before with tFileList_4?

    My job is actually this:


    0683p000009MG7x.png
    Martin
    Anonymous
    Not applicable
    Author

    TRF
    It doesn't seem to be possible to do a LEFT on an object (directory list).
    Other ideas?
    Martin
    Anonymous
    Not applicable
    Author

    Hi
    Ok, just got it: Filemask
    "([0-9]{5})" + ".*"
    Martin