ImPratham45
(Prathamesh Patil)
August 8, 2018, 8:42am
1
How to get extension of the file from an string eg: abc.pdf I want only pdf.
I try split option given below:
" Split(filep.tostring,“.”) " (Note: filep is the variable in which my files are stored.)
I got the answer but what I can do when file name is “abc.xyz.pdf”
Mr_JDavey
(Joshua Davey)
August 8, 2018, 8:47am
2
Hi there @ImPratham45 ,
You should be able to use:
strExtension = Path.GetExtension("strYourFilePath")
Which should store the necessary information within the “strExtension” variable.
Thanks in advance,
Josh
balupad14
(Balamurugan (BalaReva))
August 8, 2018, 8:47am
3
Hi @ImPratham45 ,
This way you can take all the file extensions.
Hey @chrestick
You can use Path.GetExtention(item) =“.xlsx” or Path.GetExtention(item) =“.xls”
For more assistance check this out :
Regards…!!
Aksh
Regards
Balamurugan.S
ImPratham45
(Prathamesh Patil)
August 8, 2018, 8:56am
4
@balupad14 @Mr_JDavey Actually I have one folder which contains pdf,txt,xls,xlsx,csv and many more. So I want to fetch the extension of all files. I get all file extensions by using for each using “Split(filep.tostring,“.”)” but problem occurs when file name is " xyz.abc.pdf" then it gives “abc” not pdf
pllo2ptk
(Swoodie)
August 8, 2018, 9:17am
5
Because you splitting by “.” and you have 2 dots there.
Try balupad method, where you will always get file extension.
ImPratham45
(Prathamesh Patil)
August 8, 2018, 9:23am
6
But I think @balupad14 method gives me only .xls & xlsx.files. What if there are several types of files with different extensions?
pllo2ptk
(Swoodie)
August 8, 2018, 10:05am
7
Nop,
if you will use path.GetExtension(path) you will always get an extension of file…