I am using the below method to get the file names. But it returns the entire path and I don\'t want to get the entire path. I want only file names, not the entire path.
Try GetFileName()
method:
Path.GetFileName(filename);
You could use the GetFileName method to extract only the filename without a path:
string filenameWithoutPath = Path.GetFileName(filename);
You can use this, it will give you all file's name without Extension
List<string> lstAllFileName = (from itemFile in dir.GetFiles()
select Path.GetFileNameWithoutExtension(itemFile.FullName)).Cast<string>().ToList();
System.IO.Path is your friend here:
var filenames = from fullFilename
in Directory.EnumerateFiles(targetdirectory,"backup-*.zip")
select Path.GetFileName(fullFilename);
foreach (string filename in filenames)
{
// ...
}