This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Rename files that are stored in a list in python

Hi!

I generated a list that contains 3 text files

list = [path/A.txt, path/B.txt, path/C.txt]

Now, I want to remove the paths of the filenames, so that I have:

list = [A.txt, B.txt, C.txt]

I tried to use the os.path.basename() function in a for loop:

for file in list: file = os.path.basename(file)

I know this does not work out and I have to adress the indices of the files in the list somehow, but I got stuck...

Can someone help me with this issue?

Greetings!

python lists textfiles path basename

Hello Jonas.Koch!

We believe that this post does not fit the main topic of this site.

not related to bioinformatics

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

I agree this isn't clear how it relates to bioinformatics, but here's some help

(If the paths are all the same length)

my_list=["path/A.txt", "path/B.txt", "path/C.txt"]
[x[5:] for x in my_list]

['A.txt', 'B.txt', 'C.txt']

0 answers

No answers yet.

Log in to answer this question.