Search All Directories with Sub folders Issue

Hi Guys,

I have a workflow file that excepts an input String argument (say in_Directory) which holds a directory (ex: “D:”). I’m using that to get all the folders and sub-folders in the directory provided via in_directory argument.


When I run this, I’m getting an error as below…
image

However, this works fine with below:
Directory.GetDirectories(in_Directory)
But, that doesn’t serve the purpose because I need to get all the folders and sub folders in that drive.

I searched a bit, but couldn’t find a solution… Can anyone help me to get the error resolved?

If this cannot be done, is there any work around to get the entire folder list along with all subfolders?

Thanks a lot for your help!!!

3 Likes

This is due to System.UnauthorizedAccessException (The caller does not have the required permission) for sub directories when it tries to retrieve all sub directories including system folders(like the one you are getting error for) as your user may not have permission or may be owned by another.

Do you want to get all the folders in your drives[C, D, E drives]? (they even have common/shared folders which you may not have access to)
I guess you will want only a work folder and in that case this will not error.

You can also try taking admin privileges and see if it works.

Hi @nadim.warsi,

I need to access few specified drivers. like D, & E for example. However they do not have any common/ shared folders. Then I need to get all folders and sub-folders into an array/list. That list will be later looped to find a specific set of files with a specific extension. Getting the files is fine… The problem is with the folder list :slight_smile:

I will try with a different user account as well with more privileges to see how that works

There is a ton of battle proven solutions for that already and honestly speaking a robot has so much overhead (processing and cost-wise) and can go wrong in so many ways (this access denied will be just a fraction of the tip of the iceberg) that it’s not even funny.

I mean it could work, theoretically, but it would be couple of times easier in pure code, if you want to reinvent the wheel… Why do it like this? I’m seriously curious.

1 Like

I was able to get the folder list as last.

Directory.EnumerateDirectories(in_Directory+"\", "*",SearchOption.AllDirectories)

This just worked perfectly to get the output I need… Thank you for the help :slight_smile:

2 Likes

HI… its actually a long story… I just replied to you via Messaging :slight_smile:

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