The file names are dynamic and I need to extract the file extension. The file names look like this: parallels-workstation-parallels-en_US-6.0.13976.769982.run.sh
20090209.02s1.1_sequence.txt
SRR002321.fastq.bz2
hello.tar.gz
ok.txt
For the first one I want to extract txt
, for the second one I want to extract fastq.bz2
, for the third one I want to extract tar.gz
.
I am using os module to get the file extension as:
import os.path
extension = os.path.splitext('hello.tar.gz')[1][1:]
This gives me only gz which is fine if the file name is ok.txt
but for this one I want the extension to be tar.gz
.