How to Find Specific File/Variable inside Folder

Hello everybody!
i have a problem with find file in a specific folder.

I have this Sequence:
Variable1: “C:\test\testFilePdf”
Variable2: directory.GetFiles( Variable1,“*.PDF”)
Variable3: “5004317108”

For each item in Variable2

if
item.contains(Variable3)

then else

The automation it’s ok but the PROBLEM is the completion time because inside the folder Variable1 there are 10.000 pdf
For each item the auomation need 2 minutes to find the files.

The entire workflow would need to be completed 3 days! ( i need to find 5.000 item)

There are another way to find my VARIABLE3 inside a folder?

Thanks
Loris

1 Like

you can try this

if Path.GetFileNameWithoutExtension(Item).ToString.Equals(Variable3)

Cheers

@Loris_Sambinelli
give a try on:
Using an assign activity:
left side: Results (Array of String Datatype)
right side:
Variable2.Where(Function (x) x.Contains(Variable3)).toArray

it will return an array of strings with all items from Variable2 where Variable3 is contained in the filepath

3 Likes

I believe you search through all files for every search. Thats why it takes 2 minutes.
System.IO.Directory.GetFiles(Variable1, “*”.PDF) already skims through all files. No need to loop through anything.

Just an Assign in a Try/Catch

remain very long the process (2 minute for each)

I understand your idea ( i think you have wright) but i can’t understand your trycatch.
Wich of variable is Filexists ?
Can you explain please? thanks a lot

Oh I’m sorry i didn’t explain well.

FileExists (String) gives you the FilePath\FoundFile

FileFound

can you explain your logic please with wich type do you use? thanks a lot

Type(String)

You have ginven an example: I rewrite it as you have written it originally:

in_Directory: Variable1: “C:\test\testFilePdf”
in_FileName: Variable3: “5004317108”

I wrote Variable 3 in the field to show it here but of course you need to assign it dynamically to give a new input at the start (Assign Activity)

not sure If I gor you right, so let me try

Using an assign activity:
left side: Results (Array of String Datatype)
right side:
Variable2.Where(Function (x) x.Contains(Variable3)).toArray

the LINQ statement checks each entry from variable if it contains the value of Variable3 in its item
All positive matches will be collected within an array
As mentioned above it will return an array of Strings ( String( ) )

However the solution approach from @TastyToast maybe with this variation
directory.GetFiles( Variable1,"*" + Variable3 + "*.PDF")

could help to filter it directly. So give a try on this as well

ok now i understand yuor answer and it’s perfect! thanks a lot

Finally i found why i can’t do my automation!
If i use
Directory.Getfiles(Path,“*.PDF”).Where(Function (x) x. Contains( Variable3)).ToArray
and my Variable3 is: "“C:\test\testFilePdf\INV_10004_5004317108.PDF” the automation it’s done!

But my problem is in my Variable3. My variable it’s only 5004317108

the automation with only number invoice without path crash because the results it’s nothing.

So now what i can do?