Subject:How to Process subfolders???
Posted by: luces1
Date:8/28/2005 7:45:35 PM
Good day once again. I am trying to do a script that will set the Acid Loop proerties for several files. At this point the only way that I have been able to figure out to do this is to have all of the files open in Forge that I want to alter and then have them saved and closed from Forge. Btw, this was pretty much a script that I copied verbatim from TJSony(?) because my scripting abilities really stink! Anyhow,what script or routine (if possible at all) should I use for the following: ...I have one main folder that contains all of the files in question,but many of these are located in sub folders and sub-sub folders; is there a way to have a script that will process all of these files just by selecting the main folder as the destination for these files and all of the sub folder files? And is it possible to do without each file being opened ,then closed in the Forge window...do it behind the scenes as it were? Please excuse any further questions I might have about scripting,but my aptitude for it really is crappy! I hope I have stated clearly what I want to accomplish. Thanks for the tips,luces. |
Subject:RE: How to Process subfolders???
Reply by: ghova
Date:9/2/2005 9:15:31 AM
Unfortunately, you have to iterate through each subfolder to get to the files you need. AFAIK, there's no single command that lets you see the complete contents of everything in a folder structure. ~Gil |
Subject:RE: How to Process subfolders???
Reply by: luces1
Date:9/3/2005 2:18:03 AM
bummer. well thanks for taking the time to reply! luces. |
Subject:RE: How to Process subfolders???
Reply by: _TJ
Date:9/10/2005 8:16:37 PM
To process all of the files in a folder rather than process all of the files currently open in Sound Forge, you would need to change the outer loop. If you recall, from the thread about AcidTest.cs script, we have the following code to process all of the currently open files. foreach (ISfFileHost file in app.Files) { // process each file here } If we want to process all of the files in a given folder, we would need to do this instead. foreach (string sFilename in Directory.GetFiles(@"C:\My Files", "*.wav")) { ISfFileHost file = app.OpenFile(sFilename, false, false); // process each file here. } Unless you want to end up leaving the files open in Sound Forge, you should make sure to close them in the loop. If you want to process subfolders, you will need to write some slightly more complex code, since you will need to write a couple of functions to keep the code manageable. Look for TODO in the code below to find the place where you would add code to do your file processing - Such as editing ACID info. tj using System; using System.IO; using System.Windows.Forms; using SoundForge; public class EntryPoint { public void Begin(IScriptableApp app) { // Sound Forge begins executing our script here... string sBaseFolder = @"c:\my files"; bool fAndSubfolders = true; // Call a function to process all of the files in a folder... ProcessFolder(app, sBaseFolder, fAndSubfolders); } public SfStatus ProcessFolder(IScriptableApp app, string sFolder, bool fAndSubfolders) { SfStatus status; // process all wave files in the folder. // foreach (string sFilename in Directory.GetFiles(sFolder, "*.wav")) { status = ProcessFile(app, sFilename); if (status != SfStatus.Success) return status; } // process all subfolders. // if (fAndSubfolders) { foreach (string sSubfolder in Directory.GetDirectories(sFolder, "*.*")) { status = ProcessFolder(app, sSubfolder, true); if (status != SfStatus.Success) return status; } } return SfStatus.Success; } public SfStatus ProcessFile(IScriptableApp app, string sFilename) { ISfFileHost file = app.OpenFile(sFilename, false, true); if (null == file) return SfStatus.Fail; // TODO: do your file processing here. file.Save(SaveOptions.PromptIfNoFilename); SfStatus 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; } //EntryPoint Message last edited on9/10/2005 9:09:57 PM by_TJ. |
Subject:RE: How to Process subfolders???
Reply by: luces1
Date:9/19/2005 8:57:15 AM
SonyTJ as always, you come through for me!!! I am sorry I have not given thanks sooner, but I have been on the road without adequate internet service. I will work with the script you posted and see if I can make heads or tails of it. Once again,thanks so much for "holding my hand" through my poor scripting abilities!!!! luces |