rename a file with that of another with same substring name

rename a file with that of another with same substring name

Hi,
I have some files as listed below:
sourceDirectory1: 
ABC_D5.text.yr16.info.201602.txt
ABC_D5.textsample.yr16.info.201602.txt
ABC_D5.textsam.yr16.info.201602.txt
sourceDirectory2:
ABC_text.log
ABC_textsample.log
ABC_textsam.log
Requirement1: move/copy all files (*.txt) from sourceDirectory1 to targetDirectory, as is --> DONE (achieved using tFileCopy).
Requirement2: move/copy all files (*.log)  from sourceDirectory2 to targetDirectory, but these log files must be renamed to corresponding ".txt" file    ---> I could not achieve Smiley Sad
Result:
targetDirectory:
ABC_D5.text.yr16.info.201602.txt
ABC_D5.textsample.yr16.info.201602.txt
ABC_D5.textsam.yr16.info.201602.txt
ABC_D5.text.yr16.info.201602.log --->(the actual file is ABC_text.log renamed to this)
ABC_D5.textsample.yr16.info.201602.log --->(the actual file is ABC_textsample.log renamed to this)
ABC_D5.textsam.yr16.info.201602.log --->(the actual file is ABC_textsam.log renamed to this)
Hope I am clear with the requirement, Please let me know if I missed any info to provide.
Thanks in advance.
Moderator

Re: rename a file with that of another with same substring name

Hi,
Here is an "Rename" option in component tfilecopy.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Four Stars

Re: rename a file with that of another with same substring name

Hi Raghavendra,
please follow the screenshot as a solution of ur problem.
   
Thanks,
Alok

Re: rename a file with that of another with same substring name

Thank you Sabrina and Alok ..
I'm wondering if there is a way where I can compare .txt file names from directory1 and .log file names from directory2 to match the substring such as "text" or "textsample" or "textsam", then use the matched name of .txt file to rename the .log file ..
sourceDirectory1:
ABC_D5.text.yr16.info.201602.txt
sourceDirectory2:
ABC_text.log

so ABC_text.log will be copied to target directory as ABC_D5.text.yr16.info.201602.log  instead of ABC_text.log ..
I wanted to use this approach of mapping because there will be around 50 files in a directory and 10 to 12 such directories .. so it'll take lot of in just hardcoding each file name in multiple tFileCopy components.

Re: rename a file with that of another with same substring name

Sorry typo in the last sentence ..
".. so it'll take lot of TIME in just hardcoding each file name "

Also, forgot to mention  the below point ..
Also, every month these files will be replaced in respective source directories with new files .. with names same except the month .. example, a file name that contains *.201605.txt this month, next month (in June) we will receive the file with same name except the date i.e., *.201606.txt"

Re: rename a file with that of another with same substring name

anyone .. any ideas on how to proceed further with the above issue..?   Smiley Sad
Five Stars

Re: rename a file with that of another with same substring name

I think that the requirement needs to be clear on the rule that gets you from one file name to another.
ABC_D5.text.yr16.info.201602.txt
ABC_text.log
So it looks like the commonality is "ABC" and "text".
Between these is "_D5."
You then have a String that appears to be date related.
This is followed by a known extension ".txt" or ".log".
The rules may be more complex. Is it always "_D5." or could it be "_D6."?
I would load the file names from directory 1 in to tHashInput.
I would then loop through the file names in directory 2 and then compare these to each of the file names in tHashOutput.
The comparison would use a regular expression that is constructed from the directory 2 file name, based on the rules defined above. If you get a match, then you have the target file name.
This should be very straightforward, once you understand how to construct the regular expression.

Re: rename a file with that of another with same substring name

Hi...
below are some samples for filenames convention:
ABC_xx.sometext.yr16.info.201602.txt
ABC_xx_yyyy.someothertext.yr16.info.201602.txt
ABC_xx.differenttext.yr16.info.201603.txt
ABC_xx_yyyy.newtext.yr16.info.201603.txt
Like in your reply, some files have _D5 , while some files may have _D5_PARA or _D6_something before the period of the text string. 
Commonalities:
ABC, .info. , yr16 (for next year files it will be yr17 and so on), date 201602 or 20160201 (the date portion can be yyyymm for some files and  yyyymmdd for somefiles)
PS: sorry for sharing these details very late .. I just got these details yesterday ..
Four Stars

Re: rename a file with that of another with same substring name

Hi Raghavendra,
Please find below the screenshot of the mention requirement.

  
Output :

I guess it fulfill your requirement.
Thanks,
Alok

Re: rename a file with that of another with same substring name

Hi Alok,
the output folder files is a little different than my scenario .. but the critical part is same as per your job design .. I'll give it a try and will update you ..
Four Stars

Re: rename a file with that of another with same substring name

Raghavendra,
     I designed the job as per the requirement u mentioned in the post. You try to resolve it and please let me know if I missed anywhere.