C
C#2y ago
Bino

❔ Avisynth script maker thing

Im trying to make a script that creates AVS files for every file in a Directory based on a template. Here’s what i have so far: string[] lines = Directory.GetFiles(@"H:\Cartoons, Anime und co\Jim der Regenwurm"); string text = File.ReadAllText("Template.avs"); foreach(string name in lines) text = text.Replace("[CLIP]", (name)); File.WriteAllText ("JimNew.avs", text); I can’t figure out how to make it write every path to a new file that it creates automatically. I tried using foreach but it didn’t work.
11 Replies
Angius
Angius2y ago
Well, using foreach was a good call You simply need to include that File.WriteAllText() inside of the loop
foreach (var thing in things)
Foo();
Bar();
foreach (var thing in things)
Foo();
Bar();
is the equivalent to
foreach (var thing in things)
{
Foo();
}
Bar();
foreach (var thing in things)
{
Foo();
}
Bar();
not
foreach (var thing in things)
{
Foo();
Bar();
}
foreach (var thing in things)
{
Foo();
Bar();
}
Protip: always use braces and remember that whitespace in C# doesn't define the scope, it's not Python
Bino
BinoOP2y ago
Thx for the help but i actually got my buddy to help, he made a nice thing
var templatePath = "Jim.avs";
var inputDirectory = @"H:\Cartoons, Anime und co\Jim der Regenwurm";
var outputDirectory = @"C:\Temp";
var templateText = File.ReadAllText(templatePath);
foreach (var filePath in Directory.GetFiles(inputDirectory))
{
var fileName = Path.GetFileNameWithoutExtension(filePath);
var newFileText = templateText.Replace("[CLIP]", filePath);
var outputFilePath = Path.Combine(outputDirectory, $"{fileName}.avs");
File.WriteAllText(outputFilePath, newFileText);
}
var templatePath = "Jim.avs";
var inputDirectory = @"H:\Cartoons, Anime und co\Jim der Regenwurm";
var outputDirectory = @"C:\Temp";
var templateText = File.ReadAllText(templatePath);
foreach (var filePath in Directory.GetFiles(inputDirectory))
{
var fileName = Path.GetFileNameWithoutExtension(filePath);
var newFileText = templateText.Replace("[CLIP]", filePath);
var outputFilePath = Path.Combine(outputDirectory, $"{fileName}.avs");
File.WriteAllText(outputFilePath, newFileText);
}
Anton
Anton2y ago
use EnumerateFiles instead of GetFiles
Bino
BinoOP2y ago
var finalFile = Path.Combine(outputPath, $"{fileName}.mkv"); Console.WriteLine("Merging the files"); ExecuteCmd(ffmpegPath, @$"-i ""{videoFile}"" -i ""{audioFile}"" -c copy ""{fileName}"""); void ExecuteCmd(string ffmpegPath, string v) { throw new NotImplementedException(); } trying to mux files using ffmpeg gives me an error saying not implemented var ffmpegPath = @"C:\Program Files\FFmpeg\ffmpeg.exe"; var outputPath = @"c:\Temp"; var inputPath = @"C:\EarthwormJimCartoonDVD1\VIDEO_TS\audio"; var audioFile = Path.Combine(inputPath, "$.ac3"); var videoFile = Path.Combine(inputPath, "$.mkv"); var fileName = Path.GetFileNameWithoutExtension(inputPath); var finalFile = Path.Combine(outputPath, $"{fileName}.mkv"); Console.WriteLine("Merging the files"); ExecuteCmd(ffmpegPath, @$"-i ""{videoFile}"" -i ""{audioFile}"" -c copy ""{fileName}"""); void ExecuteCmd(string cmd, string arguments) { var processInfo = new ProcessStartInfo { FileName = cmd, Arguments = arguments, CreateNoWindow = true, UseShellExecute = false }; var process = Process.Start(processInfo); process?.WaitForExit(); } full code rn
Anton
Anton2y ago
Use the library CliWrap
Anton
Anton2y ago
GitHub
GitHub - Tyrrrz/CliWrap: Library for running command-line processes
Library for running command-line processes. Contribute to Tyrrrz/CliWrap development by creating an account on GitHub.
Anton
Anton2y ago
I mean, it's fine without it, but this thing is more convenient and can escape arguments
Bino
BinoOP2y ago
Will give that a go Thx
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Bino
BinoOP2y ago
Never got around to trying
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server