|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『楼 主』:
fsutil fsinfo drives(已解决)
使用 LLM 解释/回答一下
fsutil fsinfo drives >drives.txt
for /f "skip=1 tokens=1 delims=:" %%i in (drives.txt) do set drivers=%%i
这2行有什么错误?为什么不能set drivers?
Last edited by Eblis on 2007-1-13 at 11:16 PM ]
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.
|
|
2007-1-13 09:39 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
|
2007-1-13 10:31 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
还想问个问题..find 不可以搜索2个字符串吗??
比如find /i "1.txt" "2.txt" 3.txt
搜索3.txt文件里的1.txt 和2.txt 2个字符串..
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..
|
|
2007-1-13 10:44 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
3楼问题找到答案了...用findstr命令可以...帮忙回答1楼的..
The problem on the 3rd floor has found an answer... The findstr command can be used... Help answer the question on the 1st floor.
|
|
2007-1-13 10:52 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
|
2007-1-13 11:31 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
fsutil fsinfo drives >drives.txt
for /f "skip=1 tokens=1* delims=:" %%I in (drives.txt) do @set drives=%%I %%j
我只是想把drives.txt里面的:驱动器: C:\ D:\ E:\ F:\ G:\ H:\ set drives=c d e f g h
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
|
|
2007-1-13 11:53 |
|
|
dikex
高级用户
    潜水修练批处理
积分 788
发帖 366
注册 2006-12-31
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
发现fsutil fsinfo drives >drives.txt生成的drives.txt里面虽然有内容,但其ascii码居然有很多00!a.txt的内容是从drives.txt里面复制过去的(查看大小同样为32字节),但看看FC /b比较的结果
正在比较文件 drives.txt 和 A.TXT
0000000D: 00 20
00000011: 00 20
00000015: 00 20
00000019: 00 20
0000001D: 00 20
下面的代码也出问题了……
for /f "skip=1 tokens=2-6 delims=:\" %i in ('fsutil fsinfo drives') do echo %i %j %k %l %m %n
这个只有%i显示成功,但将'fsutil fsinfo drives'换为上面那个a.txt时则成功了……
看来是fsutil fsinfo drives的输出有问题了……
这次运行fc drives.txt a.txt得到结果
***** drives.txt
驱动器: C:\
D:\
E:\
F:\
G:\
***** A.TXT
驱动器: C:\ D:\ E:\ F:\ G:\
*****
但用for /f %i in (a.txt) do echo %i 却只能显示“驱动器:”
Last edited by dikex on 2007-1-13 at 02:56 PM ]
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 ]
|
|
2007-1-13 14:01 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
不知道上面的兄弟是怎么复制的..我这里比较却是没有异处
G:\DOS\BAT>fc /b drives.txt 1.txt
正在比较文件 drives.txt 和 1.TXT
FC: 找不到相异处
G:\DOS\BAT>fc /b drives.txt 2.txt
正在比较文件 drives.txt 和 2.TXT
FC: 找不到相异处
1.txt是文件内容复制的..2.txt是copy drives.txt的..都没有不同的..
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..
|
|
2007-1-13 16:31 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
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
为什么这句之后会显示 set drives=c d e f g h %j
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
|
|
2007-1-13 17:12 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
实在想不通了..各位高手..
不会是要用到..你们说的变量延时吧????我快郁闷死了..我先用
fsutil fsinfo drives >1.txt 然后type 1.txt >2.txt 再执行for 语句还是不能成功...
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...
|
|
2007-1-13 17:38 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
***** drives.txt
驱动器: C:\
D:\
E:\
F:\
G:\
我有点明白了为什么只显示一个C了..虽然我们fsutil fsinfo drives输出到文本之后看到是一行..而实际上是换行显示的..所以for 只能显示一条的字符串....
***** 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....
|
|
2007-1-13 18:08 |
|
|
Eblis
中级用户
  
积分 251
发帖 108
注册 2007-1-7 来自 湖南==>广州
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
测试完成..是没有办法显示的..ASCII码显示前2行是回车..不清楚了...希望高手能解答一下为什么会这样显示...
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...
|
|
2007-1-13 22:19 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
fsutil fsinfo drives|find /v "">drives.txt
fsutil fsinfo drives|find /v "">drives.txt
|
|
2007-1-14 00:11 |
|
|
dikex
高级用户
    潜水修练批处理
积分 788
发帖 366
注册 2006-12-31
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by Eblis at 2007-1-13 03:31 AM:
不知道上面的兄弟是怎么复制的..我这里比较却是没有异处
G:\DOS\BAT>fc /b drives.txt 1.txt
正在比较文件 drives.txt 和 1.TXT
FC: 找不到相异处
G:\DOS\BAT>f ...
双击打开那个文本,然后全选,复制,新建一个文本,粘贴
让我们看看下图中winhex的对比结果吧,20在上面的复制前是00这个结束符的,所以for在处理这些字符串时遇到了00,就以为结束了而不继续处理下去,自然就得不到我们想要的结果了,也就是说对于for来说,它要处理的就只有驱动器: C:\这些数据,因此for /f "skip=1 tokens=2-6 delims=:\" %i in ('fsutil fsinfo drives') do echo %i %j %k %l %m %n 和 for /f %i in (a.txt) do echo %i 都只能显示出一部分来
Last edited by dikex on 2007-1-13 at 03:31 PM ]
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 ]
附件
1: 未命名.JPG (2007-1-14 04:30, 45.46 KiB, 下载附件所需积分 1 点
,下载次数: 1)
|
|
2007-1-14 04:30 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
以前玩过的一段查找盘符改的,感觉比 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
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
|
|
2007-1-14 05:45 |
|