Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need a dos script to ignore the "There is no disk in drive.." error

Posted on 2012-04-10
11
Medium Priority
?
597 Views
Last Modified: 2012-05-21
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:\thisisatestfolderdonotremove

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.
0
Comment
Question by:devinngo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 37828282
You could probably leverage WMIC to get only the attached physical logical drives. The command below should get you the disks in the server.

wmic logicaldisk where drivetype="3" get caption
0
 

Author Comment

by:devinngo
ID: 37828391
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.
0
 
LVL 7

Expert Comment

by:larry urban
ID: 37828398
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:\thisisatestfolderdonotremove
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:devinngo
ID: 37828827
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:\thisisatestfolderdonotremove  

??
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 37829646
I can help with this and will work up an approach shortly...

~bp
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 37829718
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
  )
)

Open in new window

~bp
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37835199
devinngo

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
  )
)

Open in new window

0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37835242
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:
@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"
)

Open in new window

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
  )
)

Open in new window

Notice the double-quotes around '%%d:\thisisatestfolderdonotremove\*'. This is required if there are spaces in the foldername.
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37835334
devinngo

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
  )
)

Open in new window

NOTE: When using WMIC, both 'deviceid' and 'caption' work equally well on my XP setup.
0
 
LVL 11

Accepted Solution

by:
paultomasi earned 2000 total points
ID: 37835365
devinngo

When testing code, be sure to remember it must distinguish between a folder named 'thisisatestfolderdonotremove' and a file named 'thisisatestfolderdonotremove'. All my solutions above are able to distinguish the difference.
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 37993475
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
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question