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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Fernandez
Creator II
Creator II

[resolved] How to copy files with keeping folder structure ?

Hi,
I have a folder structure with files scattered across the folders and I want to copy all files to another destination keeping the folder structure.
How can I do that ?
Regards,
Antoine
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

This is an interesting question and one that I had very recently. However, it appears to be harder than it actually is. The following will sort this for you as long as every folder of the structure you want to recreate has a file in it. The job will look like below..

0683p000009MDt0.png
The tFileList is set up like below.....

0683p000009MDQd.pngThe tFixedFlowInput outputs one column which uses one of the variables from the tFileList....

((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

The tJavaRow has the following code....

//Get file path
String fileToCopy = input_row.fileToCopy;
//Replace back slashes to forward slashes - Windows
fileToCopy = fileToCopy.replace('\\', '/');
//Set fileToCopy value
output_row.fileToCopy = fileToCopy;
//Replace the start of the path to change it to the new start or root
String outputPath = fileToCopy.toUpperCase().replaceFirst("C:/TEST", "E:/TEST/NEW_LOCATION");
//Remove the file name from the path so that only the path is left
outputPath = outputPath.substring(0, outputPath.lastIndexOf("/"));
//Output the new file path
output_row.outputFilePath = outputPath;

In the tFileCopy you need to set the "File Name" as the "fileToCopy" column and the "Desitination directory" as the "outputFilePath" column. 
This should do it for you.

View solution in original post

9 Replies
Anonymous
Not applicable

This is an interesting question and one that I had very recently. However, it appears to be harder than it actually is. The following will sort this for you as long as every folder of the structure you want to recreate has a file in it. The job will look like below..

0683p000009MDt0.png
The tFileList is set up like below.....

0683p000009MDQd.pngThe tFixedFlowInput outputs one column which uses one of the variables from the tFileList....

((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

The tJavaRow has the following code....

//Get file path
String fileToCopy = input_row.fileToCopy;
//Replace back slashes to forward slashes - Windows
fileToCopy = fileToCopy.replace('\\', '/');
//Set fileToCopy value
output_row.fileToCopy = fileToCopy;
//Replace the start of the path to change it to the new start or root
String outputPath = fileToCopy.toUpperCase().replaceFirst("C:/TEST", "E:/TEST/NEW_LOCATION");
//Remove the file name from the path so that only the path is left
outputPath = outputPath.substring(0, outputPath.lastIndexOf("/"));
//Output the new file path
output_row.outputFilePath = outputPath;

In the tFileCopy you need to set the "File Name" as the "fileToCopy" column and the "Desitination directory" as the "outputFilePath" column. 
This should do it for you.
Fernandez
Creator II
Creator II
Author

It's running fine.
Many thanks.
Antoine
Anonymous
Not applicable

Hi I used the above method to copy files from source to target. however files does not copied to destination folder. in tFileCopy i put destination directory as "outputFilePath" and filename as fileToCopy

please find my source and destination path

source D:/Documents/SourceDir/Important tables.docx

destination: D:/DESTDIR 

I used same tjava code as given.

 

also I tried using context variable for destination directory in context file.

and kept context.tgtfilepath as destination directory

context file contains  tgtfilepath=D:/DestDir

It copies the all files into destination folder. however it does not create subfolder at destination as per my source folder. Please help

in my source i have files like...

source files:

D:/Documents/SourceDir/Important tables.docx

D:/Documents/SourceDir/Other Files/File1.docx

D:/Documents/SourceDir/VPN Connection/File2.docx

 

aslo i need to check no. of source files and no of target files are same or not? how can i achieve this. please help

 

Randepp

Anonymous
Not applicable

It sounds like you may have been confused by my description. Can you give a screenshot of your job and of your tFileCopy configuration. I believe that maybe you have got the wrong values there.

Anonymous
Not applicable

Hi 

Please find my tfilecopy settings.

0683p000009M77j.png

Job executes but does not copy files/ folders from source directory to destination. also i need to copy all subfolders and files inside it to destination folder as it has structured in source (folders / subfolders / files)

 

If I used copy a directory option from tfilecopy(above), it works as I required however it copies source directory into destination directory. I need all files/subfolders(files) from source to destination directory with files/subfolders(files) in it.

 

Randeep

Anonymous
Not applicable

You've not set the columns correctly.

"File Name" should be.....

row2.fileToCopy

"Destination directory" should be....

row2.outputFilePath

This is assuming that you have configured the column in the tJavaFlex and used the same code as me

sgoardou1611911472
Contributor
Contributor

Hi,

 

7 years later, I am dealing with the same issue.

 

However, I have tried to implement the solution, but I do have the following issues:

  • fileToCopy cannot be resolved or is not a field
  • outputFilePath cannot be resolved or is not a field

 

I am using TALEND STUDIO V8.

 

 

Anonymous
Not applicable

fileToCopy and outputFilePath need to be configured in the schema of your tJavaRow component. If you have done this, then they will be available in the next component by using the row name before the column names. So, if your row is "row2" (as in the example above), they will be....

 

row2.fileToCopy

 

...and....

row2.outputFilePath

Anonymous
Not applicable

added the job demo which works for your reference