Question: How to use python to rename files in a folder with known prefix, prefix are in excel?
gravatar for szp770
11 weeks ago by
szp7700 wrote:

all. 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
python file next-gen R rename • 324 views
ADD COMMENTlink modified 4 weeks ago • written 11 weeks ago by szp7700

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 REPLYlink modified 11 weeks ago • written 11 weeks ago by Dunois500
gravatar for dcrookston
6 weeks ago by
dcrookston0 wrote:

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 COMMENTlink written 6 weeks ago by dcrookston0
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1251 users visited in the last hour