devinngo
asked on
Need a dos script to ignore the "There is no disk in drive.." error
Hello all,
I am trying to run a batch that will scan all drives to look for a folder, this issue I'm having is as soon as it his an empty DVD drive I would get the "There is no disk in drive" pop up. I need to be able to ignore this error and continue to scan, I am running this on Windows 7 64 bit.
FOR %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
IF EXIST %%d:\thisisatestfolderdono tremove
NOTE: I have seen one other posting about this issue but the fix did not work. Also I would need this in a DOS command, not vb script.
I am trying to run a batch that will scan all drives to look for a folder, this issue I'm having is as soon as it his an empty DVD drive I would get the "There is no disk in drive" pop up. I need to be able to ignore this error and continue to scan, I am running this on Windows 7 64 bit.
FOR %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
IF EXIST %%d:\thisisatestfolderdono
NOTE: I have seen one other posting about this issue but the fix did not work. Also I would need this in a DOS command, not vb script.
ASKER
xxdcmast,
Thank you, but that will not work because I still need to search through all the USB drives and devices for that folder, the purpose is to save a backup onto the drive that folder exists.
Thank you, but that will not work because I still need to search through all the USB drives and devices for that folder, the purpose is to save a backup onto the drive that folder exists.
Did you try:
FOR %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
dir /s %%d:\thisisatestfolderdono tremove
FOR %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
dir /s %%d:\thisisatestfolderdono
ASKER
so it would be something like:
FOR %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
IF EXIST dir /s %%d:\thisisatestfolderdono tremove
??
FOR %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
IF EXIST dir /s %%d:\thisisatestfolderdono
??
I can help with this and will work up an approach shortly...
~bp
~bp
Not sure exactly what logic you want to occur when you do or don't find the file, but see if this gives you some ideas.
@echo off
for /F "skip=2 tokens=2 delims=," %%A in ('wmic logicaldisk where drivetype^=3 get deviceid^,volumename /format:csv') do (
echo Checking:[%%A]
if exist "%%A\thisisatestfolderdonotremove" (
echo TRUE
) else (
echo FALSE
)
)
~bp
devinngo
Your approach is almost right however, you need to add '\*' at the end like this:
Your approach is almost right however, you need to add '\*' at the end like this:
@echo off
for %%d in (c d e f g h i j k l m n o p q r s t u v w z y z) do (
if exist %%d:\thisisatestfolderdonotremove\* (
rem
rem Your code goes here...
rem
)
)
devinngo
Another thing you can do is build a 'drives' string variable which you can use later. So, if you were to have say, drives C: D: E: and H: then your variable drives will be set to 'C D E H', like this:
tremove\*'. This is required if there are spaces in the foldername.
Another thing you can do is build a 'drives' string variable which you can use later. So, if you were to have say, drives C: D: E: and H: then your variable drives will be set to 'C D E H', like this:
@echo off
setlocal enabledelayedexpansion
set "drives="
for %%d in (c d e f g h i j k l m n o p q r s t u v w z y z) do (
if exist %%d:\* set "drives=!drives! %%d"
)
Now you can search for your folder like this:for %%d in (%drives%) do (
if exist "%%d:\thisisatestfolderdonotremove\*" (
rem
rem Your code goes here...
rem
)
)
Notice the double-quotes around '%%d:\thisisatestfolderdono
devinngo
If you decide to use WMIC then the following will work correctly.
If you decide to use WMIC then the following will work correctly.
@echo off
for /f %%a in ('wmic logicaldisk where drivetype^=3 get deviceid ^| find ":"') do (
if exist "%%a\thisisatestfolderdonotremove\*" (
echo %%a
)
)
NOTE: When using WMIC, both 'deviceid' and 'caption' work equally well on my XP setup.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Could you close this differently please? It's not clear what solution worked for you, so rather than accept the comment as the solution, please select the post(s) that actually contain the code that worked for you.
I can't see how 37835242 could have resolved the problem, since at it's core it does basically the same thing your original example posted does, and should therefore throw the same error.
If on the other hand it was 37835334 that solved your problem, then it feels like post 37829718 should have gotten some recognition as well, since it is basically the same core approach with small adjustments.
~bp
I can't see how 37835242 could have resolved the problem, since at it's core it does basically the same thing your original example posted does, and should therefore throw the same error.
If on the other hand it was 37835334 that solved your problem, then it feels like post 37829718 should have gotten some recognition as well, since it is basically the same core approach with small adjustments.
~bp
wmic logicaldisk where drivetype="3" get caption