Two Slash Problem in Directory.GetFiles

Hi,
I have been using Directory.GetFiles("…", “.xlsx”) for some time. But there occurs a problem. It gets the path with two slashes so cannot open the files. Could you please help with that?

“C:\Users\62557\Desktop\xxx\yyy\zzz.xlsx”

Thanks,
Aysegul

@aysyavuz Wrie the condition if string contains two slash than replace with single slash

Hi @aysyavuz

Use of two hashes are normal when working with file paths. The second slash is usually used for programming to mention that the string contains a slash in it. It does not make any harm. I’m working with the get files function daily and the slash was never a problem as the second one is added as a internal reference. However, you should not include more than one slash . May I know what the exact error you are getting?

2 Likes

Actually two slashes won’t give any error @aysyavuz. Anything works fine even with single slash or double slash as far as I know :slight_smile:

1 Like

Hi,
How can I write for string ? In For Each in Assign activity, I write “Files = item.Replace(”//","/")" but it gives an error.

Thanks,
Aysegul

@aysyavuz Try like this item.ToString. Replace(”//","/")

Get all the files using Directory.GetFiles(“path”) and store them in a array.you can create the array in the variables pane.

Then while iterating it using the for each activity, use assign activity and give as @indra mentioned @aysyavuz

1 Like

I can not use .ToString because my “files” variable is String Array. Is there another way?

Instead of typing the path manually, just Shift+right click on the folder from which you are selecting your files. Choose “Copy as Path” option and follow any of the below workarounds
1)paste the value in Path option in below code
2)copy the value in a variable called Path, pass this variable in below code.
Directory.GetFiles(Path)
3) Use ‘For each File in Folder’ activity which directly gives you all the code. Just give the path value into SelectFolder variable.

You shouldn’t get any error doing this

Regards,
Sravya V

Dear All,

Thank you for all your reply to my problem. We realized that two slashes is not the problem but there is an issue about some of our excels. When we omitted the ones that UiPath cannot read, it successfully continues. We are trying to find out what is the problem with those excels.

Thanks,
Aysegul