Command Line Question

kcnychief

??? ??? ?
Political Access
Joined
8 Apr 2005
Messages
16,950
Does anyone know of any slick console (cmd.exe) commands that will return the UNC path of a mapped drive with no other text? I need to isolate the UNC path to store it in a text file. So far I have this:

C:\>net use t:
Local name T:
Remote name \\server\share
Resource type Disk
Status OK
# Opens 0
# Connections 1
The command completed successfully.

But all I want is the value of the "Remote name", and I am limited strictly to console commands like dir, echo, net, and so on. A batch file would work fine if you have a set of commands that will get the same result. I am looking to append the value into a text file with a simple redirection like this:

C:\>net use t: >> UNCPath.TXT

Any DOS/cmd gurus know of any tricks to do that? It has to be something that can execute on any PC (2k or XP) without installing anything.
 
Try this in a batch file

Code:
@echo off
for /f "tokens=2,3 delims=\" %%i in ('net use %1 ^| find "[URL="file://%5C%5C"%27"]\\"'[/URL]) do echo [URL="file://%5C%5C%%i%5C%%j"]\\%%i\%%j[/URL]
just pass the drive letter as a parameter of the batchfile.. ie:

c:\> somename.bat t: >> mydestFile.txt

edit: Removed an extra backslash in the code
 
Last edited:
Worked perfectly, simply amazing.

Reps++

-edit-

Any web resources where I can learn about that - it was pretty sweet :D
 
Last edited:
Actually, that was "out of my head" so to speak.. sadly enough I didn't need to look it up (other than to remember the exact syntax of the "for" command, which you can get by typing "for /?" and the command line).

YOu can probably google "DOS Batch" and come up with some good resources though..

If you had a list of drive letters, you can actually put them all in a text file (one drive letter per line) and wrap the whole thing in another for loop

Code:
for /f %i in (driveLetterList.txt) do UNCPath.bat %i >> UNCPathList.txt
driveLetterList.txt --> List of Drive letters
UNCPath.bat --> Name of Batch file
UNCPathList.txt --> Destination file
 
Ok so I have spent quite a bit of time on this, question now is how I can shrink below 9 varialbes :dead:

For a little background, this is designed to be a clickable button in Lotus Notes that a user can click, enter the path for a file and then it will paste a URL into a message for them.

I also want to be able to go back to an 8.3 naming convention, as the output acts weird when there are spaces in the file name.

Code:
[FONT=Courier][SIZE=2]szfile := @Prompt([LocalBrowse]; "Select a file:"; "3");[/SIZE][/FONT]
[SIZE=2][FONT=Courier]@If(szfile = ""; @Return(1);[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@Contains(szfile;":\\") & !@Contains(szfile;"C:");@Do(@Command([Execute]; "cmd.exe"; "\" /c echo @echo ^^^<a href='file:^^^/^^^/%1 %2 %3 %4 %5 %6 %7 %8'^^^>^^^<font face=sans-serif size=2^^^>\\\\%1 %2 %3 %4 %5 %6 %7 %8^^^<^^^/a^^^> > ml.bat");@Command([Execute]; "cmd.exe"; "\" /c echo @for ^/f \"tokens=2,3 delims=\\\" %%i in ('net use %1 ^^^| find \"\\\\\"') do @call ml.bat %%i\\%%j\\%2 %3 %4 %5 %6 %7 %8 %9 >gUNC.bat");@Command([Execute]; "cmd.exe"; "\" /c gUNC " + @Left(szFile;"\\") + " " + @Right(szFile;"\\") + " >link.htm"));[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@Do(@Set("szLink";@ReplaceSubstring("file://" + szfile; "/":" "; "^/":"%20"));@Set("linkhtml";"^<html^>^<a href='"+szLink+"'^>^<font face=\"sans-serif, Arial, Helvetica, Geneva\" size=\"2\"^>"+szFile+"^<^/font^>^<^/a^>^<^/html^>");@Command([Execute]; "cmd.exe"; "\" /c echo "+linkhtml+">link.htm"))[/FONT][/SIZE]
[SIZE=2][FONT=Courier]);[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@Do(@Prompt([Ok];"Pause";"Press Space or Enter to continue and create the link.");[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@PostedCommand([FileImport]; "HTML"; "link.htm"))[/FONT][/SIZE]
 
damn I always feel like I am a step behind you guys. But I just wanted to say thanks because I usually learn something from your problems for the future. Its easy to feel like a idiot online and another thing to feel like that in front of your boss. lol. I will shut up now.
 
FWIW, and stop hijacking my thread :)p), I don't think your an idiot. And your ability to solve problems outside of your immediate intelligence makes you more valuable than those who can't do that.

So, chin up :)
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back