Get specific File from a Local Disk

Hi,
I need to access a csv File from a specific Location. But to access it, I need to pass through plenty of folders.
eg: CN20220603 is my csv File. To Get this file, I need to pass through the following path,
Documents/Folder1/2022/March/CN2022xxxx/CN202206xx/CN20220603.
So, Inside Folder1,we can also contain 2021,2020 folder etc… and Inside every year (ex.2022), We can have Multiple Months folder like March,April,may etcc…
So, I need to search through all these months folder first to check whether the file is available . If not found,I need to check the next Year folder(ex.2021)

Is there a way to get this CSV file CN20220603 ? or I need to pass through every single folder?

Note: The file can be inside any of the year folder or Month Folder.

Thanks in advance.

@esakkiappan.b

Try below expression to search in all subfolders inside particular parent folder.

      Directory.GetFiles("Root Folder Path","*CN20220603*.csv",SearchOption.AllDirectories)
1 Like

Hi,
Thanks for the response. This one works only if we knew the exact folder inside which my csv file can be found.
but in my example, The path , Documents/Folder1 is only common. After that, The file can be present inside ANY of the folders.
Your code just checks whether the csv file is present inside ANY of the folders of “Folder1”
For eg: The code checks whether the csv file is present inside “2022” folder, If not present, It passes empty. The root directory I passed is “Documents/Folder1”

Any other suggestions ?

@esakkiappan.b

You need to check year by year here.

This works @lakshman … It checks all the sub folders inside the parent folder which we mentioned.
Thanks and Marking it as Solution.

@esakkiappan.b

You should Mark correct post as solution but not yours :sweat_smile:.

Happy Automation :robot::v:

1 Like

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