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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Copy most recent file from one directory to another

Hi everyone.
I am trying to build a job in open studio that copies a .txt file from one location to another location. There will be a number of .txt files in the directory, but I only want to copy across the most recent one.
for example 
file1.txt
file2.txt
file3.txt
I am trying to do this based on the date modified properties.
I have looked through a few posts on here but have not managed to get any solution to work.
Would anyone be able to point me in the right direction, or even better if you have any print screen examples I could follow?
Many thanks in advance!
Labels (2)
14 Replies
TRF
Champion II
Champion II

Hi,
Did you try tFileList ordered by modification date desc tFileProperties (mtime and mtime_string fields give you the last modification date and time). You may also decide to break the iterate loop or jump over the undesired rows (see this post  https://community.talend.com/t5/Design-and-Development/Break-From-Iteration/td-p/99207).
Regards,
TRF
Anonymous
Not applicable
Author

I have tried the solution in the attached image.
I keep getting mtime = null in the tlog though. I am clearly doing something wrong?

0683p000009MDZt.png
TRF
Champion II
Champion II

Use "((String)globalMap.get("tFileList_2_CURRENT_FILEPATH"))" in tFileProperties and put a tLogRow just after this component.
I've just tested on my environment. It works like a charme.
.---------------------------------------------------------------------+------------------------------------------------+--------------------+-----------+----+-------------+----------------------------.
| tLogRow_1 |
|=--------------------------------------------------------------------+------------------------------------------------+--------------------+-----------+----+-------------+---------------------------=|
|abs_path |dirname |basename |mode_string|size|mtime |mtime_string |
|=--------------------------------------------------------------------+------------------------------------------------+--------------------+-----------+----+-------------+---------------------------=|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0170301.csv|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|xxxxxxxx20170301.csv|rw |103 |1488442149885|Thu Mar 02 09:09:09 CET 2017|
'---------------------------------------------------------------------+------------------------------------------------+--------------------+-----------+----+-------------+----------------------------'


Regards,
TRF
Anonymous
Not applicable
Author

Yes, This is working and it is now writing the most recent file properties to a tlog, which is great.
How do I use those details in the tlog to then copy the file across to a new location?
TRF
Champion II
Champion II

Just have to configure a tFileCopy with the required informations
Anonymous
Not applicable
Author

Thank you TRF.
This is the part I am struggling with. The tlogrow only has a error message or a number of lines option to feed into the tfilecopy. Using the current filepath from the tfilelist only copies across the first file it comes to in the original directory and not the most recent file.
Apologies if this is an easy task, I have only recently picked up talend again and I am trying to get up to speed.
Regards,
TRF
Champion II
Champion II

Hi,
This is not normal to have only 1 field except if tBufferInput_1 schema is not aligned.
Did you check it?
Anonymous
Not applicable
Author

Apologies I did make some changes to the job as I was not getting the tbuffer to work.
This is a print screen of my job. Up to the tlogrow everything appears to work as expected in that it outputs the file properties of the most recent file to the tlogrow.
You can see the options I have on the left in terms of what to use in the tfilecopy.
0683p000009MDW7.png
TRF
Champion II
Champion II

OK, it doesn't work like this.
Click on tLogRow then edit schema. Here are the available fields.
So in tFileCopy, you can use abs_path to indicate which file you want to copy.