I am trying to develop a small program to rename batches of files (pdf, etc). Imagine that the default is "1250_F1_001A_E01-001A00.pdf" and in the end it would get "1250_F1001A00.pdf", it kept the first 7 and the last 6 of any file. What's in the middle would be eliminated.
The problem is in fileName.LastIndexOf(3, 3));
gives error constantly.
The code I am trying to produce is as follows:
namespace RenomeiaPdfs
{
class Program
{
static void Main(string[] args)
{
const string DIRECTORY_PATH = @"C:\Users\...\RENOMEIA";
if (Directory.Exists(DIRECTORY_PATH))
{
string[] filePathList = Directory.GetFiles(DIRECTORY_PATH);
foreach (string filePath in filePathList)
{
if (File.Exists(filePath))
{
// Get the file name
string fileName = Path.GetFileName(filePath);
// Get the file extension
string fileExtension = Path.GetExtension(filePath);
// Get the file name without the midle part
string fileTitle = fileName.Substring(0, fileName.LastIndexOf(3, 3));
File.Move(filePath, DIRECTORY_PATH + @"\" + fileTitle + fileExtension);
}
}
}
}
}
}