Dynamic File Existance

Hi,

I have a scenario where I need to download the files, which can be of any file extension (.xlsx, .pdf, .tif, .doc, etc).

I need to specify the file name in advanced

Next I need to check if the that file is present in the folder or not using the same File name, but as I am not sure of file extension, then it is always giving as “No file Exists”.

I tried using — path.fileNameWithoutExtension, but still getting the same result.

How to tackle the situation?

Thanks

I am not clear with this part…Without know the file name how will you provide the file in advance…

If you could provide some sample screenshot and explain your requirement in brief we could analyze and assit …

Thanks for reply,

I know the naming convention by which I need to save the file, but not the extension, so I am saving the file by this (without specifying the type of file extension, which is been taken automatically)

But I need to check the existence of file name using “Path exists”, I don’t want to give the extension to check its existence.

Thanks

@Kajal_Singhal - sorry it is not clear again. If you can’t provide the screenshot…can you provide with some samples and explain…

Hi @Kajal_Singhal

As per your Query, You would want to compare a file name without extension with a with a file/many files (maybe) present in a directory.

Hence, Let’s say the naming convention of the file without file Extension is Stored in a variable namingConvFile

Now, Let’s get the Files from the Directory and compare the namingConvFile using the below expression :

Directory.GetFiles("YourDirPath_WhereFilesArePlaced").Any(Function(x)Path.GetFileNameWithoutExtension(x).Equals(namingConvFile))

The above expression compares files without extensions.

If the File name is already present in the Directory, it would Result in True else False.

There might be Error Scenarios that you may need to handle, if the files are empty in the Directory to search.

Let us know if this is not the expected output needed, and explain a bit more with Example case.

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