How to get file name of some specific extension

Hi Team,

We have an input folder (C:\Test) contains files of various formats (.xslx, .docx, .zip, .tab).

Is there a way we can fetch the file name (only Name, do not require extension) which is having .tab extension?
(Please note - Inside that folder, there will be only single occurrence of that particular extension).

@DewanjeeS - You can try like this…

StrFileName = Path.GetFileNameWithoutExtension(Directory.GetFiles(YourFolderPath,"*.tab").OrderByDescending(Function(d) New FileInfo(d).creationtime).First)

StrFile is of String Type

Since you already mentioned there will be only one occurence of that file, i have tried to extract the filename directly.

Sample Flow:

Input Folder (You can see I have only one exe file, and the above screenshot printed only filename without any extension)

1 Like

Directory.GetFiles(YourPath, "*.tab").Select(Function (x) Path.GetFileNameWithoutExtension(x)).toarray
is retruning an array withg the filename(s) and can be defensively postprocess to get a/the filename

1 Like

@prasath17 … Thanks Man!!! I am able to fetch file name of exact extension with the provided solution.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.