Saturday, February 4, 2012

C# get file name from file path

  String filePath = @"c:\file\neme\file.txt";

=> filePath.Split('\\')[filePath.Split('\\').Length-1]     ---->   Will give file name with extension

=> (filePath.Split('\\')[filePath.Split('\\').Length-1]).Split('.')[0] --> Will give file name without extension 


=> filePath.Split('\\')[0]  --> Will give drive letter 


No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...