Will Brode
Will Brode

Reputation: 1126

Can I get an absolute path from a network path in a batch script?

Is there any way in a batch script to take a shared network path on my computer and get the absolute path to that directory?

Example: I'm running a batch file on TESTBOX. I know the "stuff" folder on TESTBOX is shared on the network. Can I get the absolute path to "stuff"? If "stuff" were in C:\stuff then I want this:

Command = GETPATH \\TESTBOX\stuff

Result = C:\stuff

Upvotes: 0

Views: 1612

Answers (2)

Squashman
Squashman

Reputation: 14290

Any shared folders you have on your local computer can also be seen using the NET SHARE command.

H:\>net share

Share name   Resource                        Remark

-------------------------------------------------------------------------------
C$           C:\                             Default share
IPC$                                         Remote IPC
ADMIN$       C:\windows                      Remote Admin
STUFF        C:\STUFF
The command completed successfully.

So if the share name is stuff you can extract the output of the NET SHARE command into a variable by encapsulating it in a FOR /F command.

FOR /F "TOKENS=1* delims= " %%G IN ('net share ^|find /I "stuff"') DO SET sharepath=%%H

Upvotes: 0

MC ND
MC ND

Reputation: 70933

You can try to ask wmi for the share information

wmic share where "name='stuff'" get path

Upvotes: 2

Related Questions