Grab Files from a Mapped Network Drive w/o Hardcoding the Folder Path

I currently building an automation that needs to access a folder located on a network drive, however I cannot hardcode this folder path because it may change based on the user running the bot. Need maximum compatibility here.

For example the full folder path is “R:\MainFolder\MyFolder\Teamfolder\BOTFolder”

However, not all members will have the R drive selected, but maybe the S drive(“S:\MainFolder\MyFolder\Teamfolder\BOTFolder”)

The contents I need will always be in the BOTFolder located on the network

Is there an easy way to grab this location without hardcoding the full folder path so that anybody who runs the bot can access the contents?

There are two options:

1st option:
Before accessing the folder, you can check the existence of directory by using the VB command Directory.Exists() method. If Directory.Exists(“R:\MainFolder\MyFolder\Teamfolder\BOTFolder”), then go for R drive, else you can access S drive

2nd option:
If you know which users have R drive, then you can use the VB command Environment.Username to know the currently logged on user. If username matches with your users list, then use R drive, else use S drive

use the server path instead of the user defined drive name

lets say when you are mapping the drive you give your server a name
eg: Z: = \iad.local\Global


so you folder path may look something like Z:.…\YourFolder
but instead you could use - \iad.local\Global.…\YourFolder

This path will remain same irrespective of the user defined mapping

I hope that helps :slight_smile:

Is it only R and S as a drive directory?
You may want to consider also getting the environment variable. From there you will be able to get the username of the person logged on to the machine.