"File Cannot Be Opened For Writing"

I had the same problem tagging my MP3 files. I tried everything, including trying to remove read only status for files/directories...didn't work; couldn't remove. Then I remembered I had a similar problem with other files.
The culprit for me was the windows 10 Windows Security. Under Virus & threat protection I have Ransomware Protection turned on. This is what kept me from updating tags. The solution is to add MP3tag.exe to the exception list under "Manage ransomware protection". Now everything works great.

Just thought this might help other who have tag writing issues in Windows 10.

I came across this thread after I encountered a similar problem with a single WAV file. I want to share my experience because in this case I believe the problem didn't have anything to do with Windows security, permissions, etc., but with the integrity of the file.

I was tagging my WAV files collection. After having done over 2000 files successfully with Mp3tag (what a great tool it is!), I came across one WAV file which kept getting the message "File Cannot Be Opened for Writing". The rest of the files in the same folder did not get this message and were tagged just fine.

The problematic file played fine in foobar2000 and could be copied to other disks without any problem (the issue wasn't disk corruption then). When checking its integrity, foobar2000 did not report any problems. However, trying to tag it in Mp3tag always resulted in the same error message.

After trying various things (like resorting to a backup copy of the same file, etc.), I tried something similar to what someone described above: I compressed the file to FLAC and then decompressed it. This time Mp3tag created a tag for it (for the decompressed file) without any problems.

Now, when I compared the original WAV file and the one created after decompressing from FLAC, the EAC compare tool did not show any differences whatsoever. The foobar2000 Bit-compare tracks tool did not report any differences in decoded data, either. However, Duplicate Cleaner did not show the files to be identical.

No wonder, since when I checked their size, it turned out that the original file is 16 bytes longer than the one which emerged after compressing the original one to FLAC and decompressing it.

Taking all of the above into consideration, I believe the problematic file must have had some kind of glitch in its structure - the 16 additional bytes - beyond the actual audio data - which prevented Mp3tag from processing it correctly. FLAC-compressing and decompressing it resulted in the resolution of this problem - I hypothesize that it happened thanks to getting rid of the problematic extra chunk of the file.

If anyone encounters a similar problem with a WAV file, I would recommend trying the same (or similar) method - I think it should help.

See this thread on problematic wav files:

Well, I also experience the problem that the file could not be written... Read the entire thread, and played for quite some time checking rights and ownership.

And nothing worked.

Installed another MP3 tagger (Metatogger 6.0) and it has abolutely no problems with editting the tags.

Tried MP3tag after that again, and it still refuses any editing.

Conclusion, the program has a bug. Might be a diifcult one to fix, but it is broken. No excuses.

Other than that - the structure and interface looks great. Must have been a lot of work. Would be nice if that problem that so many are experiencing is looked into and fixed. The software deserves it.

Best wishes,
Frank

To issue a bug report, I think that your post lacks a number of vital pieces of information.
What kind of files do you treat? MP3? Flac? Wav? Mp4?
Have you run the unwilling files through tools that check the integrity like linked here: How to check files for errors?
How do you know that the other tagger has made it better and not worse like e.g. simply stacked further tags on top of already existing but corrupt tags?
Are the files taggable if you move them to a different folder?
And what about other programs that access the files at the same time? have you made sure that there is none running and how did you do that?
And finally: if all these local checks still so not lead to a solution, it would be nice to get a sample file.

Thank you, ok, did some checks following your instructions, and indeed some of the MP3 files had issues, although they played fine. And when they show up in MP3tag, most of them showing tags just fine, it is for a casual user not obvious there is something wrong with the file. I suppose when the software reads the files to find the tags, it can already detect issues with integrity and it would be nice if they were labelled with a mark or shown in red. So that you know something is wrong with it. That would save a lot of time investigating if it has anything to do with ownership, rights, file locked by other processes, security settings, as is also suggested as possible causes in this long thread.

Perhaps it is also an idea to clean up the thread, rather than newcomers going through all the replies that point in wrong directions. Also, if the alert was a bit more informative than just mentioning that the file could not be written - that would be a good thing too. Now I understand that it is not that the program is not able to write the files back again, it is merely that you decide not to do so because of the risk of adding more crap to a file that is already somewhat damaged or lacking the proper structure. That is in itself an excellent approach, don't mess with a damaged file to avoid more problems. But give the casual user a bit of feedback why the command can not be executed. The warning that the file could not be written should only be displayed when the software already has build the new image, and gets an unsatisfying return value from fwrite() or whatever function is used to replace the file with the new one. If is not possible to build the new file image because the source image is corrupted, than put out a different warning.

Thank you for your reply and time.

Best wishes,
Frank

I had a lot of tagging problems with old files sourced from various locations years ago (5 to 10 years). I have a feeling that some software used decades ago to rip audio were poorly written because it was generally very old files (audiobooks mostly). mp3Val was recommended to me and using it before tagging corrected 99% of the problem files. I had to go to extreme audio editing in Audacity for only a few. I recommend that little piece of software a simple first go-to for problem mp3 files providing they can be opened..

Thinking that other folks may encounter this -- yet another variant on "locked for writing" that has NOTHING to do with mp3 file integrity, disallowed characters in a tag, or file permissions -- PATH LENGTH. I've encountered the dreaded "file locked" error multiple times.

Following advice here: How to check files for errors? I tried checking the mp3 files with both foobar2000 and mp3diags. Nothing doing, mp3tag still said the file was locked.

I then modified the mp3 file itself by:

  • Converting to WAV
  • Run ClickRepair on WAV, saved to -cr.wav
  • Convert to Flac (to avoid second lossy mp3 file)

mp3tag STILL says file is locked. Whatever "it" is, it's not the audio file.

I bought some recordings of Wagner's Ring cycle from OperaDepot. He creates a folder structure like this:

AlbumName/OperaName/DiscID/DiscNumber/Files

with both AlbumName and OperaName including performers, e.g.,

Wagner - RotN - Böhm - Bayreuth - 1968/Die Götterdämmerung - Nilsson, Windgassen, Treptow, Stewart/10011/Die Götterdämmerung - 1/filename.mp3

That's a long filepath. On a hunch, I removed the OperaName/DiscID parts of that path by moving all of the DiscNumber folders up two levels.

mp3tag no longer says the files are locked!! The move shortened the filepath considerably. I thus conclude that filepath length was actually the issue and the "locked" error is itself erroneous. I think mp3tag is encountering a error condition it is not programmed to recognize, so in this case it's throwing the "locked" error which is misleading.

In Windows security, find Ransomwear protection, and uncheck the box !!!!! So effing simple! Nanny OS

Make sure you are running Mp3tag as administrator.

I had the same issue, but wasn't able to find the answer in the thread. I'm leaving my solution here in case anyone else gets stuck with the same problem.
The error "file cannot be opened for writing" only occurred when trying to add album art to freshly ripped FLAC files. What ended up working was reducing the file size on said album art. Started with 2100x2100 resolution images, but was only able to get 1800x1800 to save to files properly. Probably has something to do with file size limits for album art or some such. In any case, test changing a different attribute and see if that works. If it does, find smaller album art.

If at all, it might depend on the size in bytes that causes a limitation. The dimensions do not say a lot as this could also apply to really small files with a low quality.

FLAC has a limitation of ~16MB because the length field of the metadata block can only hold numbers up to 24bit.

There may be other software or processes locking your files, sometimes only for a short time.

A 72 dpi jpg picture with the dimension 6940x4640 takes up between 6 MB and 9 MB ...
The same picture with the dimenstion 2100x1400 takes up 1.8-2.2 MB...
The same picture with the dimenstion 1800x1200 takes up 1.3-1.8 MB...
So the reduction in size by 300x200 pixel saves about 0.6 MB ...
I am not sure if that really makes the difference.

Hi everyone, I've been struggling with this issue for ages and nothing here seemed to be working for me. It seems like this issue varies a lot case by case, so there's no guarantee this will work for anyone else, but I just stumbled upon something that solved it for me so I made an account here just so I could share.

The answer is: Windows Media Player

I noticed it running as a background process on my computer. As soon as I ended the task, suddenly the "cannot be opened for writing" error DISAPPEARED. However, Windows doesn't seem to allow WMP to be closed for any length of time because the process reappears soon after I force close it. And when the process reappears, so does the error. So I've been playing a game of "how many tags can I edit before WMP starts back up" while trying to edit this album.

My next task will probably be removing WMP entirely, because it's completely useless anyway. This malware-like behaviour of constantly re-instantiating itself is quite concerning, though, in addition to the fact that it seems to block other programs' write access to files.

Anyway, this is absolutely bizarre but I wanted to share what I found that gave me some resolution. If anyone knows any more about why this might happen then I'd love to hear it!!

WMP is a feature that can be turned off via the Control Panel.
Settings > Apps > Apps & features > Program and Features > Turn Windows features on or off > Media Features > uncheck "Windows Media Player"
Turn WMP off

I solved this issue by converting the FLAC files to WAV using Freeac, adding the 600x600 dpi artwork then converting back to fLAC. I do not use larger bitmaps as it then doesn't display the artwork in the car music player. Unfortunately, they have to be converted to MP3 as the car sound system does not recognise FLAC.