„Google“ grupės nebepalaiko naujų „Usenet“ įrašų ar prenumeratų. Istorinį turinį galima peržiūrėti.

How can I quietly test if a disk device is ready or not?

134 peržiūros
Praleisti ir pereiti prie pirmo neskaityto pranešimo

Timo Salmi

neskaityta,
2004-02-19 12:30:102004-02-19
kam:
DRAFT: (#53)

@echo off & setlocal enableextensions
if "%1"=="" (
echo Usage: %~f0 [Device:]
goto :EOF)
set ready=true
dir %1 > "%temp%\tmp$$$.dir" 2>&1
find "The device is not ready" "%temp%\tmp$$$.dir" > nul
if %errorlevel% EQU 0 set ready=false
find "The system cannot find the path specified" "%temp%\tmp$$$.dir" > nul
if %errorlevel% EQU 0 set ready=false
if exist "%temp%\tmp$$$.dir" del "%temp%\tmp$$$.dir"
if "%ready%"=="true" echo The device %1 is ready
if "%ready%"=="false" echo The device %1 is not ready
endlocal & goto :EOF

The output might be e.g.
D:\TEST>cmdfaq a:
The device a: is not ready

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

foxidrive

neskaityta,
2004-02-19 13:27:452004-02-19
kam:
On 19 Feb 2004 19:30:10 +0200, Timo Salmi wrote:

> DRAFT: (#53)
>
> @echo off & setlocal enableextensions
> if "%1"=="" (
> echo Usage: %~f0 [Device:]
> goto :EOF)
> set ready=true
> dir %1 > "%temp%\tmp$$$.dir" 2>&1
> find "The device is not ready" "%temp%\tmp$$$.dir" > nul
> if %errorlevel% EQU 0 set ready=false
> find "The system cannot find the path specified" "%temp%\tmp$$$.dir" > nul
> if %errorlevel% EQU 0 set ready=false
> if exist "%temp%\tmp$$$.dir" del "%temp%\tmp$$$.dir"
> if "%ready%"=="true" echo The device %1 is ready
> if "%ready%"=="false" echo The device %1 is not ready
> endlocal & goto :EOF
>
> The output might be e.g.
> D:\TEST>cmdfaq a:
> The device a: is not ready
>
> All the best, Timo

I'm not sure about using the term "Device" when it appears you mean a disk
drive of some kind. Perhaps lengthen it to "Storage device"?

Check this for a giggle

===[screen capture]===
D:\>cmdfaq con:
The device con: is ready

D:\>dir con:

Directory of \\.

File Not Found

D:\>cmdfaq com100:
The device com100: is ready

D:\>dir com100:
"com100:" is not a recognized device.
===[/screen capture]===

Matthias Tacke

neskaityta,
2004-02-19 14:05:042004-02-19
kam:
Timo Salmi wrote:

>DRAFT: (#53)
>
>@echo off & setlocal enableextensions
>if "%1"=="" (
>echo Usage: %~f0 [Device:]
>goto :EOF)
>set ready=true
>dir %1 > "%temp%\tmp$$$.dir" 2>&1
>find "The device is not ready" "%temp%\tmp$$$.dir" > nul
>if %errorlevel% EQU 0 set ready=false
>find "The system cannot find the path specified" "%temp%\tmp$$$.dir" > nul
>if %errorlevel% EQU 0 set ready=false
>if exist "%temp%\tmp$$$.dir" del "%temp%\tmp$$$.dir"
>if "%ready%"=="true" echo The device %1 is ready
>if "%ready%"=="false" echo The device %1 is not ready
>endlocal & goto :EOF
>
>The output might be e.g.
>D:\TEST>cmdfaq a:
>The device a: is not ready
>

Hello Timo,
depending on the os I'd use chkntfs or fsutil instead of dir.
There are some threads on this topic here and in mpwca.

--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm

Marco Maier Said

neskaityta,
2004-02-19 17:07:402004-02-19
kam:
Matthias Tacke wrote in message <news:c131cv$kb8$06$1...@news.t-online.com> :

> I'd use chkntfs or fsutil instead of dir.

Bad idea

--
Marco

Timo Salmi

neskaityta,
2004-02-20 04:44:052004-02-20
kam:
foxidrive <foxi...@Shotmail.com> wrote:
> On 19 Feb 2004 19:30:10 +0200, Timo Salmi wrote:
> > DRAFT: (#53)
> I'm not sure about using the term "Device" when it appears you mean a disk
> drive of some kind. Perhaps lengthen it to "Storage device"?

Good point.

@echo off & setlocal enableextensions
if "%1"=="" (

echo Usage: %~f0 [DiskDevice:]
goto :EOF)
for %%d in (a: b: 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 /i "%%d"=="%1" goto _set)
echo Usage: %~f0 [DiskDevice:]
echo The DiskDevice must be A: - Z:
goto :EOF
:_set


set ready=true
dir %1 > "%temp%\tmp$$$.dir" 2>&1
find "The device is not ready" "%temp%\tmp$$$.dir" > nul
if %errorlevel% EQU 0 set ready=false
find "The system cannot find the path specified" "%temp%\tmp$$$.dir" > nul
if %errorlevel% EQU 0 set ready=false
if exist "%temp%\tmp$$$.dir" del "%temp%\tmp$$$.dir"
if "%ready%"=="true" echo The device %1 is ready
if "%ready%"=="false" echo The device %1 is not ready
endlocal & goto :EOF

All the best, Timo

foxidrive

neskaityta,
2004-02-20 05:32:152004-02-20
kam:
On 20 Feb 2004 11:44:05 +0200, Timo Salmi wrote:

> @echo off & setlocal enableextensions
> if "%1"=="" (
> echo Usage: %~f0 [DiskDevice:]
> goto :EOF)

A little more versatile?


@echo off & setlocal enableextensions

if "%1"=="" goto :_Usage
set DD=%1
if %DD:~0,2%==\\ goto :_set


for %%d in (a: b: 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 /i "%%d"=="%1" goto _set)

:_Usage


echo Usage: %~f0 [DiskDevice:]
echo The DiskDevice must be A: - Z:

echo or a UNC path, beginning with \\
goto :EOF
:_set
dir %1 /-p > "%temp%\tmp$$$.dir" 2>&1
find "Volume" "%temp%\tmp$$$.dir" > nul
if %errorlevel% EQU 0 (set ready=true
) else (
set ready=false)

Matthias Tacke

neskaityta,
2004-02-20 07:36:322004-02-20
kam:
Marco Maier Said wrote:

Without telling why: useless comment!

Marco Maier Said

neskaityta,
2004-02-20 09:34:012004-02-20
kam:

>>
>>> I'd use chkntfs or fsutil instead of dir.
>>
>>Bad idea
>>
> Without telling why: useless comment!


The FSUTIL and CHKNTFS utilities work only with NTFS volumes

Matthias Tacke

neskaityta,
2004-02-20 11:39:432004-02-20
kam:
Marco Maier Said wrote:

That's interresting. Try to explain this output:

::chkntfs.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
cls
chkntfs C:
@echo Errorlevel=%errorlevel%
chkntfs E:
@echo Errorlevel=%errorlevel%
chkntfs D:
@echo Errorlevel=%errorlevel%
chkntfs C:
@echo Errorlevel=%errorlevel%
chkntfs A:
@echo Errorlevel=%errorlevel%
::chkntfs.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
==screen copy==========================================================
C:\test>chkntfs C:
Der Typ des Dateisystems ist FAT.
C: ist nicht fehlerhaft.
Errorlevel=0

C:\test>chkntfs E:
Der Typ des Dateisystems ist NTFS.
E: ist nicht fehlerhaft.
Errorlevel=0

C:\test>chkntfs D:
CHKNTFS kann nicht für das CD-ROM-Laufwerk D: verwendet werden.
Errorlevel=2

C:\test>chkntfs C:
Der Typ des Dateisystems ist FAT.
C: ist nicht fehlerhaft.
Errorlevel=0

C:\test>chkntfs A:
Abfrage des Zustandes von Laufwerk A: fehlgeschlagen
Errorlevel=2
C:\test>
==screen copy==========================================================

Marco Maier Said

neskaityta,
2004-02-20 12:15:142004-02-20
kam:
Matthias Tacke wrote in message <news:c15d8f$suv$02$1...@news.t-online.com> :

Insert a floppy,a cd or a dvd
you get the same errorlevel

--
Marco

0 naujų pranešimų