The script below works great for updating the BPM of all mp3's within a selected directory; however, when it hits an mp3 that it doesn't like, it stops with an exception error. This becomes very tedious. I was wondering if anyone could add to the script a "skip file on error" so that it continues to cycle through the mp3's, skipping past any mp3's that cause an error.
--------------------------------------
using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
public class EntryPoint {
public void Begin(IScriptableApp app) {
string folder = SfHelpers.ChooseDirectory("Choose a folder to process files from", @"C:\");
DialogResult dialogResult = MessageBox.Show("Are you sure to process " + folder + " and all its subfolders?", "WARNING", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
DirectoryInfo di = new DirectoryInfo(folder);
foreach (FileInfo file in di.GetFiles("*", SearchOption.AllDirectories))
{
ISfFileHost openedFile = app.OpenFile(file.FullName, false, true);
if(null == openedFile)
{
DPF("Could not open {0}", file.FullName);
MessageBox.Show("Could not open " + file.FullName + "\n\nThe script will now stop.", "Error", MessageBoxButtons.OK);
return;
}
uint TBPM = SfSummaryInfo.MakeFourCC('T', 'B', 'P', 'M');
ISfFileSummaryInfo sumy = openedFile.Summary;
sumy[TBPM] = "" + openedFile.ACID.Tempo;
openedFile.Close(CloseOptions.SaveChanges);
}
}
}
public void FromSoundForge(IScriptableApp app) {
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, params object [] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint