0

I'm attempting to write a .bat file

When you open cmd.exe it's defaults to C drive.

There is a mapped network drive \server.name Multiple users have access to this drive thus the drive letter is labeled differently per user.

So I want this .bat file to take DIR of the folders within \server.name or F:\ drive

My drive is mapped to F: while others might have S: So if I share the .bat file it won't work for all users.

I want to use a command that will switch the drive using the UNC path name instead of the drive letters.

Thank you.

3
  • Most cmd commands accepts UNC paths. However, you could try pushd - popd pair
    – JosefZ
    Commented Oct 18, 2016 at 23:14
  • You have given absolutely no information about what this command file will do: some applications handle UNC names, some don't. You can parse the output of net use to find which drive is mapped and, if not, which letters are available. Then change directory to that drive, mapping it first if necessary.
    – AFH
    Commented Oct 18, 2016 at 23:19
  • Welcome to Super User! Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Commented Oct 19, 2016 at 10:47

1 Answer 1

0

As other mentioned, the command prompt (CMD) doesn't read UNC/DFS paths, but you can use Powershell. For example, in a file called test.bat you can put this command

dir \\mycompany.local\Datafile

and then run

.\test.bat

To get DIR output.

If you want to run powershell from within the command prompt, you can use this in your batch file:

powershell.exe "dir \\mycompany.local\Datafile"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .