Extension


#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”


#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


#3

Hi @ImPratham45,

This way you can take all the file extensions.

Regards
Balamurugan.S


#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


#5

Because you splitting by “.” and you have 2 dots there.
Try balupad method, where you will always get file extension.


#6

But I think @balupad14 method gives me only .xls & xlsx.files. What if there are several types of files with different extensions?


#7

Nop,
if you will use path.GetExtension(path) you will always get an extension of file…


#8

@pllo2ptk Thank you!!