|
Answer» Hi
I am trying to copy a file from a server using the copy command. HOWEVER DOS won't let me use \\ to reference the correct drive. The drive isn't always the same on different PC's so I can't assume it will always be H: for example.
Please help
ThanksYou can map it in your batchfile (with an usual UNUSED drive letter). Quick and dirty:
net use y: /delete
net use y: \\share you want
xcopy ....
net use y: /delete
Or find out the correct drive with:
net use find the drive letter to the share put it in the copy command.
hope this helps uli
Hi Uli
I had thought of doing it the way you suggested but I'm worried I disconnect someone's mapped drive. Is there perhaps another way?
ThanksYes it is. If I understand right, you want to run the batch on every client and it copys a file from a server to the client. (If it should run on the server and copy FILES to clients you just have to map the client with no worry about used drive letters. You can do it in a for LOOP.)
net use shows you the mapped drives.
find "searchitem" finds the line where the mapped drive is listed. with its drive letter.
With a for statement you can get out the drive letter and put it in the copy command.
This works for me:
net use | find "search item" >share.txt
for /f "skip=2 tokens=1 delims=:" %%a in ('find "\\server\share" share.txt') do set dl=%%a echo %dl:~13,1% (Replace echo against copy...)
But it depends how the output of net use command looks on your screen. echo %dl:~13,1% Shows me one letter after the 13th letter in variable dl. (Works on NT/W2K/XP)
hope it helps uli
Being very new to this, it took me a little while to figure it all out but I think I've got the hang of it now.
On most PC's the drive I'm looking for is only mapped once but on a few of them it has been mapped twice. In this case my output file gets two entries, ie.
OK H: \\drive\folder Microsoft Windows Network OK \\drive\folder Microsoft Windows Network
Because there are two lines in the file the variable gets over-written with the last line in the file. Unfortunately it's the first line that contains the letter the drive is mapped under. I've tried various techniques to edit this file using edlin and find and replace but to no avail. Do you have any suggestions?If it always looks like the example you posted, you have ":" only in the first line, which you want.
For .....do echo %1 |find ":"
And you will only get the line with ":" To get in in variable makes a subvariable necessary....
MAYBE it is not the right way. Looks a bit strange, I wouldn´t use this myself.
Is there a drive letter which is never used? (Like y or z?) Then you could map this driveletter. Or can you do the mapping in the logonscript?
If you copy the file just once it is better to do it from your pc. You can map the pcs and it doesn´t matter which drive letters are used. (Thats what I do)
Sorry, but the longer I think about my suggestion from yesterday less I like it. Sorry.
uli
I agree that it probably isn't the best way to go about it but now I'm more interested in learning the techniques and commands.
I've got it all working now but have hit a snag. If I type each line into the command prompt everything works. But if I run it as a batch file it doesn't work.
The line 'net use | find ": \\driver\folder" > c:\share.txt' becomes 'net use | find ": \\driver\folder" 1>c:\share.txt'
Please help
|