Hello, I have the following code for processing the files in a folder and setting them to Acid oneshot. I'd like to be able to process subdirectories but can't figure out how to amend the code to do this. Can anyone help?
Thanks,
Kit
using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
public class EntryPoint {
public void Begin(IScriptableApp app) {
string strFolder = SfHelpers.ChooseDirectory("Choose a folder to process files from", @"L:\Loop Library");
if (strFolder == null)
return;
foreach (string strFilename in Directory.GetFiles(strFolder, "*.wav"))
{
SfStatus status = ProcessFile(app, strFilename);
if (status != SfStatus.Success)
{
DPF("{0} : {1}", strFilename, status.ToString());
// quit if processing or save failed.
break;
}
}
}
public bool bEnableProcessingLog = true;
public SfStatus ProcessFile(IScriptableApp app, string strFilename)
{
if (bEnableProcessingLog)
DPF("processing {0}", strFilename);
ISfFileHost file = app.OpenFile(strFilename, false, true);
if (null == file)
return SfStatus.Fail;
// TODO: do your file processing here.
// create new ACID properties object
ISfFileACIDInfo acidCurrent = file.ACID;
ISfFileACIDInfo acid = new SfFileACIDInfo();
acid.Type = ACIDLoopType.Oneshot;
acid.BeatCount = 0;
// replace current ACID properties of the file with our new object
file.ACID = acid;
// wait for processing to complete, and if it succeeds, save the file
SfStatus status = file.WaitForDoneOrCancel();
if (status == SfStatus.Success)
{
file.Save(SaveOptions.PromptIfNoFilename);
status = file.WaitForDoneOrCancel();
}
file.Close(CloseOptions.DiscardChanges);
return status;
}
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, object o) { ForgeApp.OutputText(String.Format(fmt,o)); }
public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt,o,o2)); }
public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt,o,o2,o3)); }
} //EntryPoint