# Best way to change extension of music file in library?

**URL:** <https://discourse.beets.io/t/best-way-to-change-extension-of-music-file-in-library/2102>\
**Category:** Help\
**Created:** [May 31, 2022, 11:25pm UTC](https://discourse.beets.io/t/best-way-to-change-extension-of-music-file-in-library/2102 "2022-05-31T23:25:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scuttlefish](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@scuttlefish](https://discourse.beets.io/u/scuttlefish)\
**Post date:** [May 31, 2022, 11:25pm UTC](https://discourse.beets.io/t/best-way-to-change-extension-of-music-file-in-library/2102/1 "2022-05-31T23:25:06Z")

</div>

I have a bunch of songs like this:

```auto
% beet ls -p format:MP3 path::m4a$                                                                                                                                       
/Volumes/Fantom HD/Beets/Subvader/(2011)/01 01 Starboard Roller [MP3 320].m4a

```

You can see the issue.

I need to change the extension to mp3 of tracks like these. What’s the best way to do this while keeping beets in the loop? `beets mv` is no help here.

```auto
% beet mv "Starboard Roller"                                                                                                                                             
Moving 0 items (1 already in place).

```

Thank you for the help!

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [June 1, 2022, 11:50am UTC](https://discourse.beets.io/t/best-way-to-change-extension-of-music-file-in-library/2102/2 "2022-06-01T11:50:34Z")

</div>

That’s a tricky one; beets is pretty hard-coded to preserve extensions when moving files rather than regenerating them. (That’s not necessarily wise, but it does avoid other potential problems with unexpected changes to extensions.)

Fixing this might require some manner of nuclear option. The easiest might be to remove these files from your library, rename them, and then `beet import -A` them to get them back in. A more advanced version could involve modifying the underlying database directly, but that seems like more trouble than it’s worth…

---

<div class="post-metadata">

**Author:** ![snejus](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@snejus](https://discourse.beets.io/u/snejus)\
**Post date:** [June 10, 2022, 2:03am UTC](https://discourse.beets.io/t/best-way-to-change-extension-of-music-file-in-library/2102/3 "2022-06-10T02:03:31Z")

</div>

You could loop across the filenames to rename and update the database accordingly, for example in bash:

```auto
# read all filenames into an array
IFS=$'\n' mapfile -t files < <(beet ls -p format:mp3 "path::m4a$")
# move and update
for bad_file in "${files[@]}"; do good_file=${bad_file%.m4a}.mp3; mv -i "$bad_file" "$good_file" && beet modify -y "path::$bad_file" "path=$good_file"; done

```

`mv` will prompt you before each operation, - the database won’t get updated if you choose not to move the file.

If you’re completely sure that you want to process all of them, you can remove the `-i` flag.
