I want to return the file name of the specified string without the extension
Example: The file name is “File1.txt” and return File1
How can I get this result?
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use Path.GetFileNameWithoutExtension:
DirectoryInfo dirInfo = new DirectoryInfo(currentDirName);
FileInfo[] smFiles = dirInfo.GetFiles(“*.txt”);
foreach (FileInfo file in smFiles)
{
builder.Append(Path.GetFileNameWithoutExtension(file.Name));
builder.Append(“, “);
}