中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 15:59
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » Ask: How to use batch processing to determine whether a certain sector is an idle sector?
Printable Version  2,571 / 15
Floor1 lianjiang2004 Posted 2007-06-04 16:58
金牌会员 Posts 1,884 Credits 3,946
Ask: How to use batch processing to determine whether a certain sector is an idle sector?

For example, after I use software to read sector 39, the obtained file is 039.txt, and the format is as follows:
--------------

Disk 0 Absolute Sector 39
00000004E00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000004E90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
。。。。。
Omitted

------------------

The batch processing I used is as follows, please help everyone to see, where is the problem.
----------
rem @echo off
if exist %temp%\039.txt del %temp%\039.txt >nul
diskrw 0 39 1 /l >%temp%\039.txt
For /f "tokens=1-2 delims=:" %%i In ('type %temp%\039.txt ^| find ":"') do (
set sector=%%j
echo sector is "%sector%"
pause
if not "%sector%"==" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " goto sector_2c
)

:sector_2d
echo Sector 39 is an idle sector.
echo.
pause
goto sector_2b

:sector_2c


echo Sector 39 is not an idle sector.
echo.
pause
:sector_2b

[ Last edited by lianjiang2004 on 2007-6-4 at 05:00 PM ]
Floor2 lianjiang2004 Posted 2007-06-04 17:01
金牌会员 Posts 1,884 Credits 3,946
The read - out "%sector%" has no value, I don't know why.
Floor3 lxmxn Posted 2007-06-04 17:16
版主 Posts 4,938 Credits 11,386
Variable delay is not enabled. Add "SetLocal EnableDelayedExpansion" at the beginning of the batch, then try changing %sector% to !sector!. If it doesn't work, post a follow-up to discuss.
Floor4 lianjiang2004 Posted 2007-06-04 17:20
金牌会员 Posts 1,884 Credits 3,946
Still no value. Just displayed as sector is "!sector!".
Floor5 qzwqzw Posted 2007-06-04 18:16
银牌会员 Posts 636 Credits 2,343
Even if all data is 0 it does not guarantee that this sector is unused nor does it guarantee that this sector will not be used so this can only be an auxiliary judgment method and other methods are still needed for the main judgment
Floor6 lianjiang2004 Posted 2007-06-04 18:23
金牌会员 Posts 1,884 Credits 3,946
Originally posted by qzwqzw at 2007-6-4 18:16:
Even if all data is 0

It does not guarantee that this sector is unused

Nor does it guarantee that this sector will not be used

So this can only be an auxiliary judgment method

Other methods are still needed for the main judgment


Please teach me what the main judgment method is?
I want to use an idle sector in a reserved sector.
General software will not use it, and I think there is no need to guarantee that it will not be used. Hehe, just like others can use it, I can also use it. I think as long as it is not used yet.
Floor7 terse Posted 2007-06-04 18:38
银牌会员 Posts 946 Credits 2,404
Originally posted by lianjiang2004 at 2007-6-4 17:20:
Still no value. Just displayed as sector is "!sector!".

Helped you test it, it's okay!
sector is " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
Press any key to continue...
Sector 39 is not an idle sector.
Press any key to continue...
Floor8 lxmxn Posted 2007-06-04 18:41
版主 Posts 4,938 Credits 11,386
How could there be none?

It tests normally here.
Floor9 lianjiang2004 Posted 2007-06-04 18:52
金牌会员 Posts 1,884 Credits 3,946
Strange thing, copied the content from the 8th floor, and there are values.
Floor10 lianjiang2004 Posted 2007-06-04 18:55
金牌会员 Posts 1,884 Credits 3,946
What I want is to display only the lines that are not "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" as non-free sectors. Why are all 0s also displayed as non-free sectors? What's wrong in my batch script?
Floor11 lianjiang2004 Posted 2007-06-04 18:58
金牌会员 Posts 1,884 Credits 3,946
Got it, it should be changed to if not "!sector!" == "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" goto sector_2c
Floor12 lianjiang2004 Posted 2007-06-04 19:01
金牌会员 Posts 1,884 Credits 3,946
Ask, why must the beginning part add "SetLocal EnableDelayedExpansion"? The similar batch processing I used before didn't need it. Just like the batch processing in building 1.
Floor13 lxmxn Posted 2007-06-04 19:05
版主 Posts 4,938 Credits 11,386
Search for the keyword "variable delay".
Floor14 terse Posted 2007-06-04 19:15
银牌会员 Posts 946 Credits 2,404
It's more convenient to remove the first pause.
Floor15 lianjiang2004 Posted 2007-06-04 19:20
金牌会员 Posts 1,884 Credits 3,946
Because the batch processing didn't pass, so I'm checking for errors, which has resulted in more display areas. I found that the variable there has no value, so I came to ask for help. Once solved, of course, I need to remove the useless information and just get the result. Thanks a lot.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023