Uipath error: second path fragment must not be a drive

Good day everyone,

Can I please get assisted on this: error
UiPath error: second path fragment must not be a drive
image
All this time I have been using this activity all along to access the file the file path on the shared drive and the file name hasn’t changed but all of a sudden it throws this error today:
image

Anyone please help with this

The problem is the leading ‘\’ in your search pattern

GetFiles() expects the second parameter to be only a file search pattern, not a path fragment. The pattern should not start with \.

TESTpath = “C:\Invoices”
filePath = Directory.GetFiles(TESTpath, “MDP_Payment receipt*.xlsx”).FirstOrDefault()

Thank you so much, all good now

Hi,

The issue is with the second parameter you’re passing to Directory.GetFiles. That parameter is meant to be a search pattern (like a wildcard for the file name), not a path. When you put a leading backslash \ in front of it, the system gets confused and tries to read it as a path itself, which throws the error.

Fix is simple - just remove the leading backslash from the search pattern:

Use:
filePath = System.IO.Directory.GetFiles(TESTpath, “MDP_Payment receipt*.xlsx”).FirstOrDefault()

Note: It is advisable to use System.IO.Directory instead of just Directory.