|  | 
 
| chenai79921 初级用户
 
   
 
 
 
 积分 120
 发帖 48
 注册 2007-12-1
 状态 离线
 | 
| 『楼 主』:
 [已解决]如何提取文本第一行作为新建文件夹的名字
 
使用 LLM 解释/回答一下 
 
 
例如:1.txt内容如下2131241
 6564556
 5474577
 
 现在要提取文本第一行内容,并新建文件夹的名字为第一行内容~~~?
 怎么解决?谢谢~~
 
 Last edited by chenai79921 on 2007-12-25 at 10:54 AM ]
 
For example: The content of 1.txt is as follows2131241
 6564556
 5474577
 
 Now we need to extract the content of the first line and create a new folder with the name being the content of the first line~~~? How to solve it? Thanks~~
 
 Last edited by chenai79921 on 2007-12-25 at 10:54 AM ]
 
 
 
 
 
 |  | 
|  2007-12-19 09:31 |  | 
|  | 
 
| fastslz 铂金会员
 
        DOS一根葱
 
 
 积分 5493
 发帖 2315
 注册 2006-5-1
 来自 上海
 状态 离线
 | 
| 『第 2 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
@echo offfor /f "tokens=2 delims=:" %%i in ('findstr /n . 1.txt^|findstr /b "1:"') do md %%i
 
@echo offfor /f "tokens=2 delims=:" %%i in ('findstr /n . 1.txt^|findstr /b "1:"') do md %%i
 
 
 
 
 
 
 |  
                  |  第一高手    第二高手
 我的小站
 
  |  | 
|  2007-12-19 09:54 |  | 
|  | 
 
| cad55 高级用户
 
     
 
 
 
 积分 620
 发帖 329
 注册 2007-12-5
 状态 离线
 |  | 
|  2007-12-19 10:54 |  | 
|  | 
 
| chenai79921 初级用户
 
   
 
 
 
 积分 120
 发帖 48
 注册 2007-12-1
 状态 离线
 | 
| 『第 4 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
谢谢fastslz啊~~~每次求助都有人帮忙 太感动了,,,有啥批处理的教程啊,我也想好好学学。
 
Thanks to fastslz~~~ Every time I ask for help, someone helps, so moved...Are there any batch processing tutorials? I also want to learn it well.
 
 
 
 |  | 
|  2007-12-19 11:00 |  | 
|  | 
 
| tempuser 高级用户
 
     
 
 
 
 积分 547
 发帖 261
 注册 2006-4-15
 状态 离线
 | 
| 『第 5 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by fastslz at 2007-12-19 09:54:@echo off
 for /f "tokens=2 delims=:" %%i in ('findstr /n . 1.txt^|findstr /b "1:"') do md %%i
 
tokens=2是选取文本第2列内容吗? 
delims=:是用:做分隔符吗?文本中没有分号啊! 
能否解释('findstr /n . 1.txt^|findstr /b "1:"')含义? 
谢谢,等待中... 
### 分析原代码及问题#### 关于`tokens=2 delims=:`
 - `tokens=2`:是指在使用`for /f`循环处理文本时,按照指定的分隔符分割后,获取第2个令牌(即分割后的第2部分内容)。
 - `delims=:`:是指定分隔符为冒号`:`。这里虽然文本中可能没有分号,但这里是设置分隔符的规则。
 
 #### 关于`('findstr /n . 1.txt^|findstr /b "1:"')`
 - `findstr /n . 1.txt`:`findstr`是用于查找字符串的命令,`/n`参数表示在每一行前面加上行号,`. `表示匹配所有字符(查找1.txt文件中的所有行并带上行号)。
 - `^|`:这里是转义字符,因为在命令行中`|`是管道符号,需要转义才能在`for /f`的括号内正确使用,所以`^|`表示管道符号。
 - `findstr /b "1:"`:`/b`参数表示从行首开始匹配,`"1:"`表示匹配行首为`1:`的行。所以整个部分是先找出1.txt文件中所有带行号且行首为`1:`的行。
 
 ### 翻译后的内容
 Is `tokens=2` to select the content of the second column of the text?
 Is `delims=:` to use `:` as the delimiter? There are no semicolons in the text!
 Can you explain the meaning of `('findstr /n . 1.txt^|findstr /b "1:"')`?
 Thank you, waiting...
 
 
 
 |  | 
|  2007-12-19 16:56 |  | 
|  | 
 
| chenai79921 初级用户
 
   
 
 
 
 积分 120
 发帖 48
 注册 2007-12-1
 状态 离线
 | 
| 『第 6 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
1:内容2:内容
 
 tokens=2 第二个参数为内容,, :是分隔符
 
 findstr /n  就是在匹配的每行前打印行数,,在每行的开始和1: 进行配对
 在帮助里看到的,,还有^是什么意思,我也不知
 
1: Content2: Content
 
 tokens=2 The second parameter is the content,, : is the delimiter
 
 findstr /n is to print the line number before each matched line,, pair with 1: at the beginning of each line
 
 I saw it in the help,, and what does ^ mean, I don't know either
 
 
 
 |  | 
|  2007-12-19 17:14 |  | 
|  | 
 
| huahua0919 银牌会员
 
      
 
 
 积分 1608
 发帖 780
 注册 2007-10-7
 状态 离线
 | 
| 『第 7 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by fastslz at 2007-12-19 09:54 AM:@echo off
 for /f "tokens=2 delims=:" %%i in ('findstr /n . 1.txt^|findstr /b "1:"') do md %%i
 
那是否也可以将文本的最后一行,当作文件的名字呢 
是最后一行,不是第三行;) 
那是否也可以将文本的最后一行,当作文件的名字呢是最后一行,不是第三行;)
 
 Is it also possible to take the last line of the text as the name of the file? It's the last line, not the third line;)
 
 
 
 |  | 
|  2007-12-19 18:45 |  | 
|  | 
 
| terse 银牌会员
 
      
 
 
 
 积分 2404
 发帖 946
 注册 2005-9-8
 状态 离线
 | 
| 『第 8 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by huahua0919 at 2007-12-19 18:45:
 
 那是否也可以将文本的最后一行,当作文件的名字呢
 是最后一行,不是第三行;)
 
未行应该可以:
 @echo off
 for /f "delims=" %%a in (a.txt) do set "fss=%%a"
 md "%fss%"
 
 
另第一行也可以这样的:
 @echo off
 for /f "delims=" %%a in (a.txt) do  if not defined fss set fss="%%a"
 md %fss%
 
 
Originally posted by huahua0919 at 2007-12-19 18:45:
 
 Can the last line of the text also be used as the file name?
 It's the last line, not the third line ;)
 
The last line should be okay:
 @echo off
 for /f "delims=" %%a in (a.txt) do set "fss=%%a"
 md "%fss%"
 
 
Also, the first line can be like this:
 @echo off
 for /f "delims=" %%a in (a.txt) do  if not defined fss set fss="%%a"
 md %fss%
 
 
 
 
 
 |  
                  |  简单!简单!再简单!
 |  | 
|  2007-12-19 19:11 |  | 
|  | 
 
| huahua0919 银牌会员
 
      
 
 
 积分 1608
 发帖 780
 注册 2007-10-7
 状态 离线
 | 
| 『第 9 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
简单!简单!再简单!
 第一行用的很妙!
 
Simple! Simple! Even simpler!
 The first line is very clever!
 
 
 
 |  | 
|  2007-12-19 19:16 |  | 
|  | 
 
| jmz573515 银牌会员
 
      
 
 
 积分 1212
 发帖 464
 注册 2006-12-13
 状态 离线
 | 
| 『第 10 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
@echo off
 for /f "delims=" %%i in (a.txt) do md "%%i" &exit
 
 
```@echo off
 for /f "delims=" %%i in (a.txt) do md "%%i" &exit
 ```
 
 
 
 
 
 |  | 
|  2007-12-19 20:09 |  | 
|  | 
 
| lxmxn 版主
 
         
 
 
 积分 11386
 发帖 4938
 注册 2006-7-23
 状态 离线
 | 
| 『第 11 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
set/p file=<a.txtmd %file%
 
 
```set/p file=<a.txtmd %file%
 ```
 
 
 
 |  | 
|  2007-12-20 00:48 |  | 
|  | 
 
| huahua0919 银牌会员
 
      
 
 
 积分 1608
 发帖 780
 注册 2007-10-7
 状态 离线
 | 
| 『第 12 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
Originally posted by lxmxn at 2007-12-20 12:48 AM:
 set/p file=<a.txtmd %file%
 
 
不得不佩服斑竹的功力! 
那是否也可以用同样的方法将第二行创建为一个文件夹的名字? 
Originally posted by lxmxn at 2007-12-20 12:48 AM:
 set/p file=<a.txtmd %file%
 
 
I have to admire the moderator's skills! 
Can the same method be used to create a folder name for the second line? 
 
 
 |  | 
|  2007-12-23 10:43 |  | 
|  | 
 
| lxmxn 版主
 
         
 
 
 积分 11386
 发帖 4938
 注册 2006-7-23
 状态 离线
 | 
| 『第 13 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
不行,此方法只能取文件的第一行。 
No, this method can only get the first line of the file. 
 
 
 |  | 
|  2007-12-24 00:01 |  | 
|  | 
 
| jinthree 新手上路
 
  
 
 
 
 积分 18
 发帖 8
 注册 2006-12-7
 状态 离线
 | 
| 『第 14 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
真是强,我以前碰到遇到一个问题。想用findstr找文件中一个出现的字串的那一行文本。然后再从这一行里读出第7个字串是这样处理的。看看有没有更简便的方法呢?
 
 %1 为想要查找的内容,
 
 @FINDSTR /i %1 log.txt >temp01.txt
 FOR /F "eol=; tokens=7 delims= " %%1 in (temp01.txt) do (
 Echo %%1 > temp02.txt
 goto :jump1
 )
 
 :jump1
 
It's really powerful. I encountered a problem before.I wanted to use findstr to find the line of text where a string appears in the file. Then read the 7th string from this line is handled like this. Let's see if there is a simpler way?
 
 %1 is the content to be found,
 
 @FINDSTR /i %1 log.txt >temp01.txt
 FOR /F "eol=; tokens=7 delims= " %%1 in (temp01.txt) do (
 Echo %%1 > temp02.txt
 goto :jump1
 )
 
 :jump1
 
 
 
 |  | 
|  2007-12-25 13:46 |  | 
|  | 
 
| zh159 金牌会员
 
       
 
 
 积分 3687
 发帖 1467
 注册 2005-8-8
 状态 离线
 | 
| 『第 15 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
FINDSTR放到for里面FOR /F "eol=; tokens=7 delims= " %%i in ('FINDSTR /i %1 log.txt') do Echo %%i
 
Put FINDSTR inside forFOR /F "eol=; tokens=7 delims= " %%i in ('FINDSTR /i %1 log.txt') do Echo %%i
 
 
 
 
 |  
                  |  
  |  | 
|  2007-12-25 14:03 |  |