Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Haresh
Contributor
Contributor

How to rename a file with an identifier(modified) before the extension(.csv) and copy the file to a folder if file already exists in the folder

I am trying to create a job by checking the file_name and file_size if it exists in the database,and only if the combination does not exist perform the transfer.

So as part of this in the second case scenario,if the file exists but the size differs (e.g receiving a same file_name but with different modified size)...i have to validate that it does not exist with the same exact size of the incoming file from the folder and now copy the incoming file to the destination folder with an extension filename_modified.csv

(lets say if there was an already an file namely A_B.csv with size 100 bytes -and the new file is also A_B.csv but with 500 bytes size)

In this case after validating against the database,if nb_line_processed==0 now when using tfilecopy i would want to have the file renamed and created as A_B_modified.csv with 500 bytes-meaning i dont want to replace the same existing file in the destination.

Please help,the only option is to handle this through java code(tjava)?

I tried tfileexists-its complicating the job flow a lot

And the second screenshot is my tfilecopy:

And also using this it creates the filename as A_B.csv_modified(which is wrong) -i wanted it like A_B_modified.csv?

2 Replies
Anonymous
Not applicable

I think I understand your issue here. I have knocked up a quick example of this using a tFileList to retrieve the file details. I then put together some code in a tJava to process the filename change. The code can be seen below....

 

String filename = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));

String extension = ((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"));

String newFilename = filename.replace("."+extension, "_modified")+"."+extension;

globalMap.put("newFilename", newFilename);

 

System.out.println(newFilename);

 

You can use the filename from the globalMap by using the rename tickbox in your tFileCopy and using this code for the value in the globalMap...

 

((String)globalMap.get("newFilename"))

 

I hope this helps

Haresh
Contributor
Contributor
Author

Thanks for your response,but i am looking to rename the already existing(old) file in the folder when the new incoming file of the same name is coming through such that the new file will retains its name and all the old files should be renamed as filename_old_modified_timestamp.extension...How to change the pre-existing old files in this case?