shenwei356/brename

renaming files and including folder/directory name in it

Closed this issue · 1 comments

Hello,

I have 500 folders and each folder contains about 5 files. I want to rename those files and include folder name with it.

For example:

My folders (sample1_1, sample2_2, sample3_3) look like this:

sample1_1: bin.1.permissive.fa bin2.orig.fa
sample2_2: bin.1.permissive.fa bin2.orig.fa
sample3_3: bin.1.permissive.fa bin2.orig.fa

Now, I want to rename in a way that files look like this:

sample1_1: sample1_bin.1.fa sample1_bin2.fa

In other words, I need the following 2 things to be changed:

  1. Include folder name in the file but after removing last part of it.
  2. Remove middle part of the file i.e. permissive, orig etc.

I couldn't find this type of data in your examples otherwise your renaming tools looks great.

Many thanks in advance!

  1. Removing .permissive and .orig

     brename -R -p .permissive
     brename -R -p .orig
    
  2. Appending directory name with rush.

     find -name "*.fa" | rush 'cd {/}; mv {%} {/%}_{%}'
    
  3. Removing the _1 in the file name.

     brename -R  -p '_\d+_' -r _