Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Batch: Check if drive is in use

I need to check if a drive (Z:) is in use (e.g. in use by an application, opened).

My Batch File looks like this:

Mount Z:
wait 15 minutes
check if drive Z: is in use

IF NOT: unmount Z:
ELSE: wait 15 minutes
repeat..

Is there any Command for this? Thanks!

like image 767
Jan Levers Avatar asked Sep 01 '25 02:09

Jan Levers


1 Answers

Use the IF EXIST or IF NOT EXIST combination:

:FindDrive
if exist Z:\nul goto Mounted
timeout /T 5
goto FindDrive
:Mounted

NUL is the a 'virtual' file that exists in every folder. So if c:\anypath\nul exists, the drive exists.

like image 114
James K Avatar answered Sep 03 '25 04:09

James K