# Error with Directory.GetFiles

**URL:** <https://forum.uipath.com/t/error-with-directory-getfiles/422490>\
**Category:** Studio\
**Tags:** studio\
**Created:** [May 11, 2022, 9:07am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490 "2022-05-11T09:07:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![salladinne](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salladinne/32/176935_2.png) [@salladinne](https://forum.uipath.com/u/salladinne)\
**Post date:** [May 11, 2022, 9:07am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/1 "2022-05-11T09:07:29Z")

</div>

Hey, I’m getting a strange error with a fairly straightforward GetFiles method - it seems like for some reason the method confuses the boundaries between folder Path and search pattern. Please take a look:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/2/6/4/2642a49c86d2093e4e66356a358cf8ab80c4790c.png)

the error that I get is:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/9/d/1/9d108a77319f5340b8bb745124a9a313265cb5d0.png)

It seems like it doesn’t identify the comma separating arguments correctly, and includes part of the search pattern in the folder path. Why is that? Appreciate all help

---

<div class="post-metadata">

**Author:** ![lakshman](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lakshman/32/523490_2.png) [@lakshman](https://forum.uipath.com/u/lakshman)\
**Post date:** [May 11, 2022, 9:18am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/2 "2022-05-11T09:18:25Z")

</div>

@salladinne

Write comma before **“\*.pdf”** instead of plus.

---

<div class="post-metadata">

**Author:** ![mv3mkobayashi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mv3mkobayashi/32/303526_2.png) [@mv3mkobayashi](https://forum.uipath.com/u/mv3mkobayashi)\
**Post date:** [May 11, 2022, 9:25am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/3 "2022-05-11T09:25:06Z")

</div>

検索パターンにスラッシュが入力されているからではないでしょうか！

![image](https://global.discourse-cdn.com/uipath/original/4X/0/d/7/0d76d4aa6f16a1168441a5666227921347a2726e.png)

---

<div class="post-metadata">

**Author:** ![Sam\_Abraham](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sam_abraham/32/176935_2.png) [@Sam\_Abraham](https://forum.uipath.com/u/Sam_Abraham)\
**Post date:** [May 11, 2022, 9:37am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/4 "2022-05-11T09:37:21Z")

</div>

Hi @salladinne ,

You can check the below steps and resolve the issue :

1. Check whether such a path exists  
2.Can add the folder path to a variable and use it as shown below:  
`Directory.GetFiles(WorkPath,"*.pdf*")`

Thanks,  
Sam

---

<div class="post-metadata">

**Author:** ![salladinne](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salladinne/32/176935_2.png) [@salladinne](https://forum.uipath.com/u/salladinne)\
**Post date:** [May 11, 2022, 9:52am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/5 "2022-05-11T09:52:51Z")

</div>

It will create three arguments (two commas) in total - the method only accepts two, so I get a compliation error

---

<div class="post-metadata">

**Author:** ![salladinne](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salladinne/32/176935_2.png) [@salladinne](https://forum.uipath.com/u/salladinne)\
**Post date:** [May 11, 2022, 9:53am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/6 "2022-05-11T09:53:25Z")

</div>

Doesn’t seem to be related to the slash - I get similar error on other invoices which don’t have slash

---

<div class="post-metadata">

**Author:** ![ptrobot](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ptrobot/32/175001_2.png) [@ptrobot](https://forum.uipath.com/u/ptrobot)\
**Post date:** [May 11, 2022, 11:00am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/7 "2022-05-11T11:00:13Z")

</div>

Are you sure that your filenames contain slash? Slash is usually an illegal character in filenames in Windows/Linus/MacOS since it’s being used as directory separator.

---

<div class="post-metadata">

**Author:** ![lakshman](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lakshman/32/523490_2.png) [@lakshman](https://forum.uipath.com/u/lakshman)\
**Post date:** [May 11, 2022, 11:00am UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/8 "2022-05-11T11:00:17Z")

</div>

@salladinne

> [@salladinne](#):
>
> It will create three arguments (two commas) in total - the method only accepts two, so I get a compliation error

We can use either of the one here to read pdf files from folder.

Find pdf file from parent and it’s sub folders.

```
      Directory.GetFiles("Folder Path","*.pdf", SearchOption.AllDirectories)

```

Find pdf file from specific folder.

```
      Directory.GetFiles("Folder Path","*.pdf")

```

---

<div class="post-metadata">

**Author:** ![salladinne](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salladinne/32/176935_2.png) [@salladinne](https://forum.uipath.com/u/salladinne)\
**Post date:** [May 11, 2022, 12:12pm UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/9 "2022-05-11T12:12:18Z")

</div>

But _pdf doesn’t solve the search pattern, I need other variables there - so  
Directory.GetFiles(“Folder Path”,"_.pdf") is not enough,  
It also doesn’t explain why the Method takes whatever is after the comma (being second argument) as path folder (first argument)

---

<div class="post-metadata">

**Author:** ![salladinne](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salladinne/32/176935_2.png) [@salladinne](https://forum.uipath.com/u/salladinne)\
**Post date:** [May 11, 2022, 12:17pm UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/10 "2022-05-11T12:17:46Z")

</div>

Yes, analyzed it once again and it’s definitely the slash - must have influenced the Directory.GetFiles that it instead of giving out message “illegal character in search pattern”, it twisted into thinking that name of the file is part of the folder name itself.

Thanks for help guys, I will mark the solution

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [May 14, 2022, 12:18pm UTC](https://forum.uipath.com/t/error-with-directory-getfiles/422490/11 "2022-05-14T12:18:27Z")

</div>

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