China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask: How to use batch processing to determine whether a certain sector is an idle sector? View 2,383 Replies 15
Original Poster Posted 2007-06-04 16:58 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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 ]
Windows 一键还原
http://www.yjhy.com
Floor 2 Posted 2007-06-04 17:01 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
The read - out "%sector%" has no value, I don't know why.
Windows 一键还原
http://www.yjhy.com
Floor 3 Posted 2007-06-04 17:16 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
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.
Floor 4 Posted 2007-06-04 17:20 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Still no value. Just displayed as sector is "!sector!".
Windows 一键还原
http://www.yjhy.com
Floor 5 Posted 2007-06-04 18:16 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
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
Floor 6 Posted 2007-06-04 18:23 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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.
Windows 一键还原
http://www.yjhy.com
Floor 7 Posted 2007-06-04 18:38 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
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...
Floor 8 Posted 2007-06-04 18:41 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
How could there be none?

It tests normally here.

@echo off
SetLocal EnableDelayedExpansion
For /f "tokens=1-2 delims=:" %%i In ('type 009.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
)
pause
Floor 9 Posted 2007-06-04 18:52 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Strange thing, copied the content from the 8th floor, and there are values.
Windows 一键还原
http://www.yjhy.com
Floor 10 Posted 2007-06-04 18:55 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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?
Windows 一键还原
http://www.yjhy.com
Floor 11 Posted 2007-06-04 18:58 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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
Windows 一键还原
http://www.yjhy.com
Floor 12 Posted 2007-06-04 19:01 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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.
Windows 一键还原
http://www.yjhy.com
Floor 13 Posted 2007-06-04 19:05 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Search for the keyword "variable delay".
Floor 14 Posted 2007-06-04 19:15 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
It's more convenient to remove the first pause.
Floor 15 Posted 2007-06-04 19:20 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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.
Windows 一键还原
http://www.yjhy.com
Forum Jump: