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-23 07:32
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Extract the line-by-line content of the file and perform operations. Problem! Please ask the experts to help solve it! View 4,035 Replies 24
Floor 16 Posted 2006-06-12 11:24 ·  中国 江苏 苏州 电信
中级用户
★★
过度热情
Credits 321
Posts 139
Joined 2006-03-21 17:19
20-year member
UID 52521
Gender Male
Status Offline
Thanks.!
willsort
Moderator
Floor 17 Posted 2006-06-12 12:44 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
How to extract the content of the first line of a txt file and use this line content to rename the file? Can you process multiple files at once?
Floor 18 Posted 2006-06-12 17:51 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
###

How to extract the content of the first line of a txt file and use this line of content to rename this file?
Can multiple files be processed at once?
###

The following code basically meets your requirements:

@echo off
setlocal ENABLEDELAYEDEXPANSION
for %%i in (%*) do (
set /p filename=<%%i
ren %%i "!filename!%%~xi"
)
endlocal
Floor 19 Posted 2006-06-12 21:30 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
First, thank you to the moderator!
But it doesn't seem to work!
Can you explain the function of each line of code, thank you!!!
Floor 20 Posted 2006-06-12 21:52 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
I changed "%*" to "*.txt", but it doesn't work for files with space in the file name. I hope the moderator can improve it.
Also, I still don't understand the meaning of the code. Can the moderator explain it again?
Thanks!
Floor 21 Posted 2006-06-12 22:35 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
If the file name has spaces, the solution is the same as when the path has spaces, just add quotes.
Floor 22 Posted 2006-06-13 11:44 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline

Thanks to the moderator first!
But it doesn't seem to work!
Can you explain the function of each line of code, thank you!!!
I changed "%*" to "*.txt" and it works, but it doesn't work for files with space in the file name. I hope the moderator can improve it. ...

It needs parameters when running, and it can handle cases with spaces in my test. set /p filename=<%%i is used to read the content of the first line of the text. Several commands are very simple, you can refer to Help and Support and should be able to understand it yourself. You can create a shortcut of this batch processing in the sendto directory, so that you can directly select batch renaming with the mouse.
Floor 23 Posted 2006-06-13 19:25 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
Today I studied it and basically understood it.
But there are still some doubts and I want to ask the moderator. Is "%*" referring to "*.*"? Are the parameters you mentioned also referring to "*.*"? If I want to modify txt, I can input: "1 *.txt", is my understanding correct?
Also, the usage of "do ( )" in the for statement is something I've seen for the first time (that is, "()" after do). There doesn't seem to be an introduction in Help and Support. Can you introduce its usage?
Floor 24 Posted 2006-06-14 09:59 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
Please check the CALL /? help. This means all parameters of the batch processing. I think the person upstairs made a mistake because they were not clear about this.
Floor 25 Posted 2006-06-14 14:19 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
Thanks to post 24!
I happened to see in the CALL /? help today and finally understand!!!
But where is the introduction to the "do ( )" usage of the for statement? Can post 24 answer it, thanks!!!
Forum Jump: