map network drive from text file

August 12, 2009 at 19:00:58
Specs: Windows XP
I am trying to create a batch file that will read a text file consisting of a list of servers. I want the batch file to map a drive, copy a file, then delete the mapping for each server in the text file.

what I have so far, but I can't seem to get it work. Any help you can provide is greatly appreciated.

for %%f in (serverlist.txt) do (
net use x: \\%%f\c$ password /u:domain\username
xcopy c:\AAAIssues\test\*.* x:\test\*.* /s/e
net use x: /del
)
exit

****
my text file (serverlist.txt) consist of a list of servers that looks similar to:

shark12
whale12
kangaroo22


See More: map network drive from text file

Report •


#1
August 12, 2009 at 21:03:19
The first thing I notice is that there is a missing parameter (/f) in the bat. Maybe this litle detail will make all difference.

for /f %%f in (serverlist.txt) do (
....__.....


Report •

#2
August 12, 2009 at 21:11:06
That's a good point.

Also, the default for XCOPY [also COPY DIR etc] is all files, so you can eliminate the *.* from this line:

xcopy c:\AAAIssues\test\*.* x:\test\*.* /s/e


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#3
August 13, 2009 at 17:25:27
Thanks! It's running through all of my servers now, but errors out on mapping the drive. I can't seem to figure out how to pull that variable (%%f, or each server in txt file) into my mapping line.

for /f %%f in (serverlist.txt) do (
net use x: \\<what do I need right here?>\c$ password /u:domain\username
xcopy c:\AAAIssues\test\ x:\test\ /s/e
net use x: /del
)

***************
I've tried:
1. %%f
2. set server= and then put the word 'server' there
3. %server%
4. If I put a server name there, it will map to that server for each server in list.... obviously! ...but I wanted to see it run at least for each server in list so I know that part is working.

Thanks for the help! I'm still trying to learn.


Report •

Related Solutions

#4
August 13, 2009 at 21:25:24
Having used net use previously, it might be that it takes a
while to map and unmap the drive.

put this at the top:
echo wscript.sleep(5000)>temp.vbs
and this after each net use line:
temp.vbs
and this at the very end (before exit):
del temp.vbs


good luck

Not quite clueless


Report •

#5
August 14, 2009 at 05:37:45
bluegeko: <what do I need right here?>
%%f If that's not working, make sure the echo isn't off, so you can see what, exactly, it does.

xterm11: it takes a while to map and unmap the drive.
It does take a while, but the command won't return until it's mapped or unmapped, so you don't need to wait.


Report •

#6
August 14, 2009 at 07:16:50
Razor:

Actually I had this problem before. I was trying to un-map then
map a network drive, but it was not completing; the drive wasn't actually disconnected until a moment later, it couldn't map it over the old one. So I had it pause for a few seconds, and it solved the problem.

There are no stupid questions, just stupid people.


Report •

#7
August 14, 2009 at 16:11:53
I finally got it working. Thanks for everyone's help!! I ended up with the following:

for /f %%f in (servers.txt) do (
net use x: /del
net use x: \\%%f\c$ password /u:domain\userID
xcopy c:\AAAIssues\test\*.* x:\test\*.* /s/e
)


Report •


Ask Question