How to use python to rename files in a folder with known prefix, prefix are in excel?
1
0
Entering edit mode
3.9 years ago
szp770 ▴ 10

I want to rename 970 files in a folder. The name is like this "ENCFF207HQD.bam" and so on. And the prefix I want to use is in an excel. The existing prefix is in the second column, and the prefix I want to use is in the third column, How to use information in the excel to rename all the files correctly each by each. Thanks!

Excel like this:

9   ENCFF006UXO ETS1-human
10  ENCFF468AKT ETS1-human
11  ENCFF000YFF ATF1-human
12  ENCFF000YFI ATF1-human
13  ENCFF990JRT GATA2-human
14  ENCFF778HCA GATA2-human
15  ENCFF257UWF EZH2-human
16  ENCFF083IDB EZH2-human
17  ENCFF788FFM HDAC8-human
next-gen python R • 1.2k views
ADD COMMENT
0
Entering edit mode

Could you perhaps indicate what your file names look like as they are now? Are they actually named something like ENCFF006UXO.bam or is it more along the lines of ENCFF006UXO_somethingsomething.bam?

Also, your column 1 and column 2 there have a many-to-one relationship. For instance:

ENCFF006UXO ETS1-human
ENCFF468AKT ETS1-human

Does this mean that those two files (ENCFF006UXO_something.bam and ENCFF468AKT_something.bam) should get concatenated (merged together) into one file named ETS1-human_something.bam?

ADD REPLY
0
Entering edit mode
3.8 years ago
dcrookston • 0

First, export your Excel file to comma-separated value (.csv) format. This will allow you to use Python's CSV module to read your prefix file.

You can do the actual file renaming using os.rename .

ADD COMMENT

Login before adding your answer.

Traffic: 1801 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6