Sunday, October 2, 2016

Audacity Project Check Error

In an odd turn of events, my laptop died. Now, I have a backup on network storage, so I wasn't too concerned about all my Audacity project files. At least, not until after I attempted to restore them.

It turns out that at some point in the past, maybe during backup, maybe at another time, my Audacity .aup files all got renamed to include something like a date and time stamp "Filename (2016_04_27 02_27_25 UTC).aup" Some of my .aup files are duplicated with different values. When I attempt to open the .aup files, I get a message similar to the following:


I've tried to rename the .aup files but I get the same error. Further research shows that the .au files in the _data folders have also been renamed. I confirmed that if I renamed those files by removing the date and time information, the count in the message above is reduced by that number of files for which I've renamed. Furthermore, I can see the audio in the file that was added after clicking OK which wasn't there before. Therefore, the solution to this error is to rename all the .au files by removing the date and time information.

Unfortunately, that is easier said than done. The .au files are small chunks of audio and for my meager library of recordings, there are literally thousands of .au files. Additionally, some of those files do not have the added date and time information and if I were to rename the files, they would either replace the one without the date and time information or they would create a (Copy 1) type designation. Neither of which I want to do.

The short answer is that we need PowerShell to do this if we don't want to spend days correcting these file names.
If you do not know PowerShell and aren't able to follow my instructions, please Google it. I'm not a PowerShell expert and don't have the time or energy to train someone on what I do know. The internet has a lot of tutorials out there so use them first before asking me questions. 
Naturally, the absolute first thing you should do is back up your files. I will not be held responsible for any damage that befalls your data as a result of this solution. I also recommend that you copy the damaged projects to a new directory that is short and easy to get to. My script is using C:\TEMP\Audacity.

Now, copy the following lines and paste them into a file of whatever name you like, just make sure that the file ends with the .ps1 extension. I'll call my file "FixAudacity.ps1".

Get-ChildItem C:\TEMP\Audacity -Filter "*(*).au" -Recurse | Rename-Item -NewName {$_.Name -replace '\s\u0028.+$','.au'} -Force -ErrorAction SilentlyContinue

Get-ChildItem C:\TEMP\Audacity -Filter "*(*).au" -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue

Get-ChildItem C:\TEMP\Audacity -Filter "*(*).aup" -Recurse | Rename-Item -NewName {$_.Name -replace '\s\u0028.+$','.aup'} -Force -ErrorAction SilentlyContinue

Get-ChildItem C:\TEMP\Audacity -Filter "*(*).aup" -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue


Save this to C:\TEMP. To run the file, you'll need to open PowerShell, search your computer for Windows PowerShell and right-click, then select Run as Administrator.

At the prompt, you'll need to set the execution policy that will allow you to run PowerShell scripts. type the following and press enter:

Set-ExecutionPolicy bypass

You will be prompted with a warning. Go ahead and click on "Yes". After running the script, if you are concerned, you can change "bypass" to "restricted" and PowerShell scripts won't run anymore.

Now, at the prompt, type the following and hit enter:

.\FixAudacity.ps1

Depending on the size of your library, it may take a little while to complete, but you'll know that it's done when the prompt reappears. That's it, all you have to do now is test the *.aup files by double-clicking them. If Audacity opens without the error then this worked and you can now copy all the files back into your Audacity Projects folder. Remember to have a backup elsewhere and it is best to delete all the projects that you were correcting prior to copying the fixed ones in. This will ensure that we do not keep any of the bad files.

On some occasions you may get the following error about orphaned files.


As the dialog states, there is no real harm in keeping the files. I have found that all my files work just fine, some data may have been lost but I wouldn't remember what it was so I opted to choose the delete permanently option (after I first verified there were no problems with the continue option).

Incidentally, I believe that the source of the problem with the files being renamed (and probably orphaned) had something to do with Windows backup or File History. My suggestion is that you may want to manually back up this folder to date-named folders on a separate drive to prevent this from happening again.

No comments:

Post a Comment