Reputation: 252
I'm running a batch file
cd desktop
net use z: \\NETWORKCOMPUTER1-PC\i
z:
cd movies
dir > c:movies.txt
cd ..\shows
dir > c:shows.txt
cd ..\anime
dir > c:anime.txt
net use z: /delete
At the end it gives this message:
"There are open files and/or incomplete directory searches pending on the connection to z:.
Is it OK to continue disconnecting and force them closed? (Y/N) [N]:"
At which time I select 'N' and all the text files are created correctly.
How do I make it not delete the network connection until it's done creating the last text file?
Resolved - Needed to switch back to c: before deleting the z: network connection.
Upvotes: 2
Views: 3325
Reputation: 20179
It's because you're setting z:
as the current drive near the top of your script.
So, to avoid the message, right before you attempt to delete the z:
mapping set the current drive to c:
(or whatever other drive you wish).
For example, something like this:
NET USE Z: \\ComputerName\FolderShare
Z:
REM Do some stuff here with files/folders on Z:
REM Change current drive to C: before removing the network drive.
C:
NET USE Z: /DELETE
Upvotes: 3