Look for multiple files in a drive or shared drive

Hey guys,

How to lookup for multiple files present inside a drive or shared drive.
Let’s say there are multiple files with different extensions, which are to be verified in a drive.
How can it be verified.

1 Like

@NiranjanKN

Directory.GetFiles() then loop thru these array.

cheers :smiley:

Happy learning :smiley:

5 Likes

Hi,
arr_filepath = Directory.GetFiles(“yourfolderpath”)

where arr_filepath is a variable of type array of string
this will store all the files in that folder as a array
then to verfify whether we have the file we want to be or not
–use a for each loop and pass the above variable as input
and change the type argument as string in the property panel of for each activity
–inside the loop use a IF condition like this
item.ToString.Contains(“yourfilename”)
if true it will get into THEN part where we can have our activities we want

kindly try this and let know for any queries or clarification
Cheers @NiranjanKN

1 Like

@NiranjanKN

If you want to find files in sub folders then try below one.

        Files [] = Directory.GetFiles("Folder path",SearchOption.AllDirectories)
1 Like

@NiranjanKN,

You can get the files with different extensions using this line of code,

Directory.EnumerateFiles("C:\path", "*.*", SearchOption.AllDirectories).Where(Function(s) s.EndsWith(".mp3") OrElse s.EndsWith(".jpg"))

What do you want to verify with those files?

2 Likes

@Palaniyappan

Thank you and one more doubt as to:
In this item.Tostring.Contains(“filename”)
What if I need to search multiple files in that string.

1 Like

Let’s take like we have multiple Filename we want in a array variable named arr_files
Now in the same IF expression mention like this
arr_files.Contains(item.ToString)

Where item is the variable from for each loop

Cheers @NiranjanKN

@sarathi125 @Palaniyappan @lakshman

I just want to verify if the drive contains files with different extensions.
Let’s say I’ve a one .mp3 .txt .xlsx file with specific names. I just need to verify I’ve all those files in that specific drive.

Yes, then you can do like this inside a IF activity,

Directory.EnumerateFiles("C:\path", "*.*", SearchOption.AllDirectories).Where(Function(s) s.EndsWith(".mp3") AndAlso s.Contains("yourmp3FileName")).Count > 0

This will return if the count is greater than 0, means that you can a mp3 file with the specific name.

Sameway you can do for rest of the file types.

1 Like

Awesome
—get the array of file name from the folder
arr_filepath = Directory.GetFiles(“yourfolderpath”)

—and now use a writeline activity like this
IF(Path.GetFileExtensions(arr_filepath).Contains(“mp3”) AND Path.GetFileExtensions (arr_filepath).Contains(“txt”) AND Path.GetFileExtensions (arr_filepath).Contains(“xlsx”),”True”,”False”)

Cheers @NiranjanKN

1 Like

Thanks a lot @pattyricarte @Palaniyappan

2 Likes

@NiranjanKN

No worries happy to help here.

cheers :smiley:

Happy learning :smiley:

5 Likes

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