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-24 16:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » fsutil fsinfo drives View 2,795 Replies 18
Original Poster Posted 2007-01-13 09:39 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
There is no error in the code itself in terms of basic syntax. However, the issue might be that when you do `set drivers=%%i`, if there are multiple drives, this will only capture the last drive. Also, the way you are parsing the `drives.txt` file might need to be adjusted depending on exactly what you are trying to achieve. But based on the provided code, the error as described "why can't set drivers" is a bit unclear. The code is supposed to capture the drive letters from `drives.txt` after skipping the first line and then set the `drivers` variable to each drive letter, but if you want to collect all drives, you need to accumulate them instead of just overwriting `drivers` each time.

In English: There is no inherent error in the code itself in terms of basic syntax. However, the problem might be that when you do `set drivers=%%i`, if there are multiple drives, this will only capture the last drive. Also, the way you are parsing the `drives.txt` file might need to be adjusted depending on exactly what you are trying to achieve. But based on the provided code, the statement "why can't set drivers" is a bit unclear. The code is supposed to capture the drive letters from `drives.txt` after skipping the first line and then set the `drivers` variable to each drive letter, but if you want to collect all drives, you need to accumulate them instead of just overwriting `drivers` each time.
Floor 2 Posted 2007-01-13 10:31 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
Oh, come on... Help me, please``
Floor 3 Posted 2007-01-13 10:44 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
Still want to ask a question.. Can find not search for 2 strings??
For example, find /i "1.txt" "2.txt" 3.txt
Search for the two strings 1.txt and 2.txt in the 3.txt file..
Floor 4 Posted 2007-01-13 10:52 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
The problem on the 3rd floor has found an answer... The findstr command can be used... Help answer the question on the 1st floor.
Floor 5 Posted 2007-01-13 11:31 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
Brothers, please help out, yeah.
Floor 6 Posted 2007-01-13 11:53 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
fsutil fsinfo drives >drives.txt
for /f "skip=1 tokens=1* delims=:" %%I in (drives.txt) do @set drives=%%I %%j

I just want to take the : drive: C:\ D:\ E:\ F:\ G:\ H:\ in drives.txt and set drives=c d e f g h
Floor 7 Posted 2007-01-13 14:01 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
I found that the drives.txt generated by fsutil fsinfo drives >drives.txt has content, but there are many 00s in its ASCII code! The content of a.txt was copied from drives.txt (the size is also 32 bytes when checked), but look at the result of FC /b comparison


Comparing files drives.txt and A.TXT
0000000D: 00 20
00000011: 00 20
00000015: 00 20
00000019: 00 20
0000001D: 00 20


The following code also has a problem...
for /f "skip=1 tokens=2-6 delims=:\" %i in ('fsutil fsinfo drives') do echo %i %j %k %l %m %n

Only %i is displayed successfully, but when 'fsutil fsinfo drives' is replaced with the above a.txt, it is successful...
It seems that the output of fsutil fsinfo drives is problematic...

This time running fc drives.txt a.txt gets the result

***** drives.txt

Drive: C:\
D:\
E:\
F:\
G:\

***** A.TXT

Drive: C:\ D:\ E:\ F:\ G:\
*****


But using for /f %i in (a.txt) do echo %i can only display "Drive:"

[ Last edited by dikex on 2007-1-13 at 02:56 PM ]
Floor 8 Posted 2007-01-13 16:31 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
I don't know how the brother above copied.. There is no difference here for me.
G:\DOS\BAT>fc /b drives.txt 1.txt
Comparing files drives.txt and 1.TXT
FC: no differences encountered
G:\DOS\BAT>fc /b drives.txt 2.txt
Comparing files drives.txt and 2.TXT
FC: no differences encountered

1.txt is the content of the file copied.. 2.txt is copy drives.txt.. there are no differences..
Floor 9 Posted 2007-01-13 17:12 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
for /f "skip=1 tokens=2-10 delims=:\ " %%a in (2.txt) do @set drives=%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j

Why does this line later display set drives=c d e f g h %j
Floor 10 Posted 2007-01-13 17:38 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
Really can't figure it out..各位高手..
Could it be that I need to use the so-called variable delay???? I'm almost depressed.. I first used
fsutil fsinfo drives >1.txt then type 1.txt >2.txt then execute the for statement and still can't succeed...
Floor 11 Posted 2007-01-13 18:08 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
***** drives.txt

Drive: C:\
D:\
E:\
F:\
G:\

I kind of understand why only one C is displayed.. Although when we output fsutil fsinfo drives to a text, it's in one line.. But actually it's displayed with line breaks.. So for can only display a single string....
Floor 12 Posted 2007-01-13 22:19 ·  中国 广东 广州 白云区 电信
中级用户
★★
Credits 251
Posts 108
Joined 2007-01-07 11:33
19-year member
UID 75721
Gender Male
From 湖南==>广州
Status Offline
The test is completed.. It's impossible to display.. The first two lines before ASCII code display are carriage returns.. I'm not clear... Hope experts can explain why it displays like this...
Floor 13 Posted 2007-01-14 00:11 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
fsutil fsinfo drives|find /v "">drives.txt
Floor 14 Posted 2007-01-14 04:30 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
Originally posted by Eblis at 2007-1-13 03:31 AM:
I don't know how the brother above copied.. There is no difference in my comparison here
G:\DOS\BAT>fc /b drives.txt 1.txt
Comparing files drives.txt and 1.TXT
FC: No differences found
G:\DOS\BAT>f ...

Double-click to open that text, then select all, copy, create a new text, and paste



Let's take a look at the comparison result of WinHex in the following figure. The 20 was the 00 end mark before copying above, so when for was processing these strings, it encountered 00 and thought it was the end and didn't continue processing, so it naturally couldn't get the result we wanted. That is to say, for the for command, the data it needs to process is only Drive: C:\ and so on. Therefore, for /f "skip=1 tokens=2-6 delims=:\" %i in ('fsutil fsinfo drives') do echo %i %j %k %l %m %n and for /f %i in (a.txt) do echo %i can only display part of it

[ Last edited by dikex on 2007-1-13 at 03:31 PM ]
Attachments
未命名.JPG
Floor 15 Posted 2007-01-14 05:45 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
I used to play with a segment of code for finding drive letters and modifying them. I feel it's slightly more efficient than the one on floor 15.
@echo off
for /f "tokens=1*" %%i in ('fsutil fsinfo drives^|find /v ""') do (
for /f "tokens=1* delims=:" %%n in ("%%j%%i") do (
call set drive=%%drive%%%%n
)
)
echo %drive%
pause
exit
Forum Jump: