Operating on windows 10 32bit at the moment unfortunately. I'm editing cuesheets to match back up with mp3s and m4bs whose file names have changed. I'm looking for a method to easily automate the process. Because I generally name cuesheets to match the name of the paired audio file, I thought the simplest method would just be to grab it's own file name (hopefully without it's file extension). I have the regex to select the text I want to replace working just fine in notepad++ and several other apps as well. Sadly, I have yet to find a prebuilt find and replace solution that has the file's own name that is being edited as a variable. So, I spent some time searching and the most promising thing I found was in another post (Use filename as variable when replacing text in files).
Example line in cue file:
FILE "Alfred Minoa.1998 - Animals of The Sahara - Documentary.m4b" MP4
Portion to be replaced:
Alfred Minoa.1988 - Animals of The Sahara - Documentary
New names of m4b & cue file:
Alfred Minoa - Animals of The Sahara - Documentary.cue
Alfred Minoa - Animals of The Sahara - Documentary.m4b
Goal is to replace text "Alfred Minoa.1998 - Animals of The Sahara - Documentary" inside the cue file with name of the cue file minus the ".cue" file Extension.
Updated and now working code thanks to input from Fildor
Update: Figured out the last tidbit Solved
Here's the code for anyone that might be looking to acheive the same thing or something similar.
var files = new DirectoryInfo(@"D:\TestFolder\).GetFiles("*.cue", SearchOption.AllDirectories);
foreach(var fileInfo in files)
{
var text = File.ReadAllText(fileInfo.FullName);
string TrimmedText = fileInfo.Name; // Get Filename into String
TrimmedText = TrimmedText.Substring(0, TrimmedText.Length - 4); // Trim File Extension from filename
text = Regex.Replace(text, @"(?<=FILE "").+?(?=\...."")", TrimmedText); // Replace "pattern" with filename
File.WriteAllText(fileInfo.FullName, text);
}
Thank you to those who took the time to contribute.
Don't know what your search string is trying to do, but you could try this.
Regex syntax sometimes varies between languages but seeing you are using LinqPad, you can use the Ctrl-Shift-F1 to test the search part of the regex in C# (but not the replace)