中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-05 12:38
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » [Help] Problem with batch renaming of text files
Printable Version  1,782 / 8
Floor1 venchia Posted 2007-07-14 15:23
初级用户 Posts 11 Credits 125
For example, there are several text files in a certain folder. I want to extract the first two lines of these text files and combine them to change the names of the text files. I don't know how to do it.

For example, there is this file

Moshidou.txt

The content of the file is as follows


  Moshidou
  Author: Xu Qifeng


【Content Introduction】

  Zhang Rufei, who is proficient in martial arts, accidentally came into contact with an unidentified flying object from planet K after a drunk, and accidentally obtained six pills with the effect of "the six stars of the Southern Dipper master life". These pills can bring back to life people who have died from accidental injuries and quickly restore them to the state before death.
  From then on, Zhang Rufei embarked on an extraordinary path.


There are 4 half-width characters in front of the file, but since it will be deformed here, two full-width characters are used instead

Now I want to extract the first line and the second line of the file and combine them into the form "《Moshidou》Author: Xu Qifeng.txt". I don't know if it can be done. Thank you
Floor2 ccwan Posted 2007-07-14 16:12
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Try this:
Floor3 ccwan Posted 2007-07-14 16:15
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Hehe, add the book title marks:
Floor4 venchia Posted 2007-07-15 02:30
初级用户 Posts 11 Credits 125
I want to do it in batch, not individually. Also, even using a.txt doesn't work. I tested with the following attached files and it failed. For example, the following several files are supposed to be renamed at one time as:
"Magic Fighter" Author: Xu Qifeng.txt
"X逍遥 Seeking Qin Biography" Author: Chu Lingtian.txt
"Monster Biography" Author: Lan.txt. But still, thank you.

Attachments
temp.rar (1.28 KiB)
Floor5 jmz573515 Posted 2007-07-28 21:08
银牌会员 Posts 464 Credits 1,212
```
set fso=createobject("scripting.filesystemobject")
set folder=fso.getfolder(".")
for each file in folder.files
if ucase(right(file,3))="TXT" then
with fso.opentextfile(file)
n="《" & trim(.readline) & "》"
n=n & trim(.readline) & ".txt"
.close
end with
file.name=n & ".txt"
end if
next
```
Floor6 slore Posted 2007-07-28 21:27
铂金会员 Posts 2,478 Credits 5,212
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.getfolder(".")
For Each file In folder.files
If UCase(Right(file,3)) = "TXT" Then
With
fso.OpenTextFile(file)
n = "" & Trim(.ReadLine) & ""
n = n & Trim(.ReadLine)
.
Close
End With
file.name = n & ".txt"
End If
Next

Set
folder = Nothing
Set
fso = Nothing

VBS scripts are still convenient for string processing
Floor7 ccwan Posted 2007-07-29 09:02
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Originally posted by venchia at 2007-7-15 02:30:
I need batch processing, not single processing

Also, even using a.txt doesn't work. I tested with the following attached files and failed

For example, the following several files are intended to be renamed at one time as

"Magic Fighter" ...


Your test failed because of full-width and half-width issues.
Tested the following code with your attachment and it succeeded.

Floor8 venchia Posted 2007-08-05 14:32
初级用户 Posts 11 Credits 125
I couldn't get on before, and just as I got on, I found many solutions. Thanks to all the kind friends above
Floor9 venchia Posted 2007-08-05 15:04
初级用户 Posts 11 Credits 125
Originally posted by ccwan at 2007-7-29 09:02 AM:

Your test failed due to full-width and half-width issues.
Tested the following code with your attachment and it succeeded.

[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023