Reputation: 494
I need to rename a few files systematically. So I have a list of names I want the file names to rename in. The folder consists of wav
files, that are named like:
VP01.wav
VP02.wav
VP03.wav
The order in the ID_list
is already the right order. So basically I want that VP01
will be 01_a
, VP02
will be 03_a
, etc. I tried to do it like this:
ID_list = ['01_a', '03_a', '04_b', '01_b', '05_a', '04_a', '03_b']
import os
path = glob.glob('filepath\*.wav')
for item in path, ID_list:
os.rename(item, item)
But it gives me:
TypeError: rename: src should be string, bytes or os.PathLike, not list
as error. The files I want to change are wav
files.
Does someone know how to do it?
Upvotes: 0
Views: 178
Reputation: 21759
Here's a way to do:
from pathlib import Path
file_path = Path("path_containing_wav_files/")
path = file_path.glob('**/*.wav')
for en, x in enumerate(path):
x.rename(ID_list[en] + '.wav')
Upvotes: 1