Solved

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

Posted on 2012-03-13
2
1,041 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 83

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now