Solved

edit batch to remove error output "device not ready"...

Posted on 2012-03-13
2
1,069 Views
Last Modified: 2012-03-27
how can I make the below script not display a mesaage "Device not ready" as error output?  I think it is refering to a CD or floppy drive that ready.  


(for %%i in (C D E F G) do (dir %%i:\*bquest /s /b /ad))>dir_search.txt
for /f "tokens=* delims=" %%x in (dir_search.txt) do (
    attrib +r "%%x\keycode" >NUL 2>&1
0
Comment
Question by:icecom4
2 Comments
 
LVL 1

Assisted Solution

by:disconnectedinyak
disconnectedinyak earned 250 total points
ID: 37717362
The part that does the DIR can send its errors to null

dir %%i:\*bquest /s /b /ad 2>NUL

Open in new window



untested code.. likely an error or two, but I hope it helps


(for %%i in (C D E F G) do (dir %%i:\*bquest /s /b /ad 2>NUL))>dir_search.txt
for /f "tokens=* delims=" %%x in (dir_search.txt) do (
    attrib +r "%%x\keycode" >NUL 2>&1

Open in new window

0
 
LVL 84

Accepted Solution

by:
oBdA earned 250 total points
ID: 37726869
Here's a version that will only search drives that exist on the system, lets you define the drive type(s) to scan, and you can exclude certain drive letters as well:
@echo off
setlocal enabledelayedexpansion
REM *** Define the drive types to scan:
set ScanTypes=2 3
REM *** 2: Removable drive (Floppy / USB)
REM *** 3: Local hard disk
REM *** 4: Network drive
REM *** 5: CDROM
REM *** 6: RAM disk
REM *** Define drive letters (including colon) to exclude:
set SkipDrives=A: B:
set ScanDrives=
for /f "skip=1 tokens=1,2" %%a in ('wmic.exe logicaldisk get deviceid^,drivetype') do (
  set Drive=
  for %%d in (%ScanTypes%) do (if "%%b"=="%%d" (set Drive=%%a))
  for %%d in (%SkipDrives%) do (if "%%a"=="%%d" (set Drive=))
  set ScanDrives=!ScanDrives! !Drive!
)
echo Scanning Drives: %ScanDrives%
for %%i in (%ScanDrives%) do (dir %%i\*bquest /s /b /ad 2>NUL))>dir_search.txt
for /f "delims=" %%x in (dir_search.txt) do (
  attrib +r "%%x\keycode" >NUL 2>&1
)

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

809 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