rename files (preferably using python) -



rename files (preferably using python) -

i can not manage solve problem, hope can help me.

i have several folders, containing files *.gz , need modify name shown in illustration below.

i thinking creating dictionary {filenames:[ list spliting "_"]} , bring together 1 time again changing order of 001_r1 r1_001 "os.rename", there must improve way.

thanks help.

old name:

folder1/ f02_tagctt_l005_r1_001.fastq.gz f02_tagctt_l005_r1_002.fastq.gz folder2/ j02_tagctt_l005_r1_001.fastq.gz j02_tagctt_l005_r1_002.fastq.gz

new name:

folder 1/ f02_tagctt_l005_001_r1.fastq.gz f02_tagctt_l005_002_r1.fastq.gz folder2/ j02_tagctt_l005_001_r1.fastq.gz j02_tagctt_l005_002_r1.fastq.gz

if have gnu userspace, i'd utilize rename command:

rename _r1_ _ *.gz rename .fastq.gz _r1.fastq.gz *.gz

otherwise, in python, list directories, filter on extension (or whatever), map rename function , phone call os.rename on each pair of original , new names.

python file rename

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -