自己修改文件吧,代码添加到ChangeName()中 Public SourcePgm As String Public MyArr As Variant Public MyDir As Variant Public Num As String Public Txt1 As String Public Txt2 As String Public Dir As String Public flags As Boolean Public Sub ChangeName(Source As String, Direct As String) '添加代码 End SubPrivate Sub Command1_Click() If MsgBox("这将是不可修复的,请确认!", vbOKCancel) Then MyDir = Split(MyArr(i), "\", -1, vbTextCompare) Dir = MyDir(0) For i1 = 1 To UBound(MyDir) - 1 Dir = Dir & "\" & MyDir(i1) Next i1
For i = 0 To Num - 1 Open MyArr(i) For Input Access Read As #1 MyDir = Split(MyArr(i), "\", -1, vbTextCompare) flags = False Do While Not EOF(1) ' 循环至文件尾。
Input #1, mystring ' 将数据读入变量。 If Len(mystring) >= 7 Then a = InStr(1, mystring, Txt1, vbTextCompare) If a >= 0 Then b = InStr(a, mystring, Txt2, vbTextCompare) If b >= 0 Then c = Mid(mystring, a + 7, b - a - 7) Form1.Caption = c Direct = c & ".htm"
flags = True Exit Do End If End If End If Label2.Caption = CInt(Label2.Caption) + 1 Loop Close #1
If flags = True Then ChangeName MyArr(i), Direct End If Next i
Else End If End SubPrivate Sub Form_Load() Txt1 = "<title>" Txt2 = "</title>" With CommonDialog1 '开文件问话框 .Filter = "html Files (*.html;*.htm)|*.html;*.htm" .FilterIndex = 3 .flags = &H200 .ShowOpen SourcePgm = .FileName End WithDim a As Variant MyArr = Split(SourcePgm, " ", -1, 1) Num = UBound(MyArr) + 1 Label1.Caption = "共选择了" & Num & "个文件" Form1.Caption = SourcePgm End Sub
CLS INPUT FILE1$ :rem 文件名 B$ = "<TITLE>" d$ = "</TITLE>" OPEN FILE1$ FOR INPUT AS #1 WHILE NOT EOF(1) LI = LI + 1 LINE INPUT #1, a$ bak$ = a$ VA1 = INSTR(a$, B$) IF VA1 THEN : c$ = MID$(bak$, VA1 + LEN(B$)): GOTO 20 VA1 = 0 WEND END 20 bak$ = c$ c$ = UCASE$(c$) va2 = INSTR(c$, d$) over$ = LEFT$(bak$, va2 - 1) over1$ = LEFT$(over$, 8) PRINT over1$,"ok" CLOSE #1 SHELL "ren " + FILE1$ + " " + over1$ + ".html" :rem 改名 这是我用QB4.5编的程序,已经通过,希望你取其精华,改成自己的程序!
to :itmouse 我取出了title,你接着批量改文件名吧,我该吃饭去了,今天发工资,高兴
给你两个函数,别忘了引用Scripting Runtime库Function BetweenText(strFullText As String _ , strBeginText As String _ , strEndText As String _ , Optional blnInclude = False) As String Dim lngStartPos As Long, lngEndPos As Long Dim lngLength As Long Dim lngI As Long
lngLength = Len(strFullText)
If lngLength = 0 Then Exit Function
If strBeginText = "" Then lngStartPos = 1 Else lngStartPos = InStr(1, strFullText, strBeginText) If lngStartPos = 0 Then Exit Function Else lngStartPos = lngStartPos + Len(strBeginText) End If End If
If strEndText = "" Then lngEndPos = lngLength + 1 Else lngEndPos = InStr(lngStartPos, strFullText, strEndText) If lngEndPos = 0 Then Exit Function End If End If
If blnInclude = True Then BetweenText = strBeginText & BetweenText & strEndText End If End Function Function fileText(ByVal strFileName As String) As String Dim intHandle As Integer
On Error GoTo ERROR_HANDLE
intHandle = FreeFile
Open strFileName For Binary Access Read As #intHandle
fileText = Space$(LOF(intHandle))
Get #intHandle, , fileText
Close #intHandle Exit Function
ERROR_HANDLE: fileText = "" End FunctionPrivate Sub Command2_Click() Dim FSO As New FileSystemObject Dim FLD As Folder Dim F As File Dim filePath As String Dim fileData As String Dim NewName As String filePath = InputBox("Where is your root directory of HTML?", "Input Directory", filePath)
If Dir(filePath, vbDirectory) = "" Then MsgBox "File path [" & filePath & "] do not exist!" Exit Sub End If Set FLD = FSO.GetFolder(filePath)
For Each F In FLD.Files fileData = fileText(F.Name) NewName = BetweenText(fileData, "<TITLE>", "</TITLE>") & ".htm" ' NewName = BetweenText(fileData, "<title>", "</title>") & ".htm" F.Copy "C:\temp\" & NewName Next F End Sub
不好意思!能改成其它名字吗?
另,你是把这个作为一个工具呢,还是作为模块在VB或网页中引用?
用VB写个程序,用文本格式打开HTML文件,然后寻找<title>起头</title>结尾的字符串,它之间的内容就是标题拉,然后就改名吧!
改成的名字是该文件的标题title回Anti猫:
我是准备把它作为一个小工具使用,因为对我来说可能用的比较多吧回zxb365:
过程我是知道的,但是具体如何实现就不清楚了希望有时间、有热心的VB大虾帮帮我!!!!!!!!我只要最后的程序就可以了
至于代码乱不乱、美观不美观,都无所谓再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!
声明一个XMLDocument,Load文件
Public SourcePgm As String
Public MyArr As Variant
Public MyDir As Variant
Public Num As String
Public Txt1 As String
Public Txt2 As String
Public Dir As String
Public flags As Boolean
Public Sub ChangeName(Source As String, Direct As String)
'添加代码
End SubPrivate Sub Command1_Click()
If MsgBox("这将是不可修复的,请确认!", vbOKCancel) Then
MyDir = Split(MyArr(i), "\", -1, vbTextCompare)
Dir = MyDir(0)
For i1 = 1 To UBound(MyDir) - 1
Dir = Dir & "\" & MyDir(i1)
Next i1
For i = 0 To Num - 1
Open MyArr(i) For Input Access Read As #1
MyDir = Split(MyArr(i), "\", -1, vbTextCompare)
flags = False
Do While Not EOF(1) ' 循环至文件尾。
Input #1, mystring ' 将数据读入变量。
If Len(mystring) >= 7 Then
a = InStr(1, mystring, Txt1, vbTextCompare)
If a >= 0 Then
b = InStr(a, mystring, Txt2, vbTextCompare)
If b >= 0 Then
c = Mid(mystring, a + 7, b - a - 7)
Form1.Caption = c
Direct = c & ".htm"
flags = True
Exit Do
End If
End If
End If
Label2.Caption = CInt(Label2.Caption) + 1
Loop
Close #1
If flags = True Then
ChangeName MyArr(i), Direct
End If
Next i
Else
End If
End SubPrivate Sub Form_Load()
Txt1 = "<title>"
Txt2 = "</title>"
With CommonDialog1 '开文件问话框
.Filter = "html Files (*.html;*.htm)|*.html;*.htm"
.FilterIndex = 3
.flags = &H200
.ShowOpen
SourcePgm = .FileName
End WithDim a As Variant
MyArr = Split(SourcePgm, " ", -1, 1)
Num = UBound(MyArr) + 1
Label1.Caption = "共选择了" & Num & "个文件"
Form1.Caption = SourcePgm
End Sub
INPUT FILE1$ :rem 文件名
B$ = "<TITLE>"
d$ = "</TITLE>"
OPEN FILE1$ FOR INPUT AS #1
WHILE NOT EOF(1)
LI = LI + 1
LINE INPUT #1, a$
bak$ = a$
VA1 = INSTR(a$, B$)
IF VA1 THEN : c$ = MID$(bak$, VA1 + LEN(B$)): GOTO 20
VA1 = 0
WEND
END
20
bak$ = c$
c$ = UCASE$(c$)
va2 = INSTR(c$, d$)
over$ = LEFT$(bak$, va2 - 1)
over1$ = LEFT$(over$, 8)
PRINT over1$,"ok"
CLOSE #1
SHELL "ren " + FILE1$ + " " + over1$ + ".html" :rem 改名
这是我用QB4.5编的程序,已经通过,希望你取其精华,改成自己的程序!
我取出了title,你接着批量改文件名吧,我该吃饭去了,今天发工资,高兴
, strBeginText As String _
, strEndText As String _
, Optional blnInclude = False) As String
Dim lngStartPos As Long, lngEndPos As Long
Dim lngLength As Long
Dim lngI As Long
lngLength = Len(strFullText)
If lngLength = 0 Then Exit Function
If strBeginText = "" Then
lngStartPos = 1
Else
lngStartPos = InStr(1, strFullText, strBeginText)
If lngStartPos = 0 Then
Exit Function
Else
lngStartPos = lngStartPos + Len(strBeginText)
End If
End If
If strEndText = "" Then
lngEndPos = lngLength + 1
Else
lngEndPos = InStr(lngStartPos, strFullText, strEndText)
If lngEndPos = 0 Then
Exit Function
End If
End If
BetweenText = Mid(strFullText, lngStartPos, lngEndPos - lngStartPos)
If blnInclude = True Then
BetweenText = strBeginText & BetweenText & strEndText
End If
End Function
Function fileText(ByVal strFileName As String) As String
Dim intHandle As Integer
On Error GoTo ERROR_HANDLE
intHandle = FreeFile
Open strFileName For Binary Access Read As #intHandle
fileText = Space$(LOF(intHandle))
Get #intHandle, , fileText
Close #intHandle Exit Function
ERROR_HANDLE:
fileText = ""
End FunctionPrivate Sub Command2_Click()
Dim FSO As New FileSystemObject
Dim FLD As Folder
Dim F As File
Dim filePath As String
Dim fileData As String
Dim NewName As String
filePath = InputBox("Where is your root directory of HTML?", "Input Directory", filePath)
If Dir(filePath, vbDirectory) = "" Then
MsgBox "File path [" & filePath & "] do not exist!"
Exit Sub
End If
Set FLD = FSO.GetFolder(filePath)
For Each F In FLD.Files
fileData = fileText(F.Name)
NewName = BetweenText(fileData, "<TITLE>", "</TITLE>") & ".htm"
' NewName = BetweenText(fileData, "<title>", "</title>") & ".htm"
F.Copy "C:\temp\" & NewName
Next F
End Sub
为表示歉意,再加20分!!!!!!!!!!!!!!!!!!!!!!
为表示歉意,再加20分!!!!!!!!!!!!!!!!!!!!!!
为表示歉意,再加20分!!!!!!!!!!!!!!!!!!!!!!
为表示歉意,再加20分!!!!!!!!!!!!!!!!!!!!!!
为表示歉意,再加20分!!!!!!!!!!!!!!!!!!!!!!
为表示歉意,再加20分!!!!!!!!!!!!!!!!!!!!!!我的信箱是 [email protected]
我的信箱是 [email protected]
我的信箱是 [email protected]
我的信箱是 [email protected]
我的信箱是 [email protected]
我的信箱是 [email protected]
我的信箱是 [email protected]
为表示歉意,再加20分!!!!!!!!!!!!!!!!!!!!!!
没想到这么多朋友帮助我!
多些多谢!等allen和猫儿给我发完程序(有源码更好),我即给大家散分!!!!!!!!!!!!!!并且多谢沧浪客、zxb365等等热心朋友,多谢了!散分不会忘了大家地!!!^_^再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!再加10分!
如再参与还加分!保证散分!已经80分了!加了4次,20+20+10+20+10!如果愿意把源代码公布出来,我愿意为大家作贡献,我个人多给他加10分。哈哈哈
你用msn吗?或者新浪的那个QQ?相同的字符是我自己输入然后过滤掉你说的没错
打开文件可以使用 FSO
分析源码时可以使用几个和字符串相关的函数。
老报错
VB怎么过滤这些特殊字符
猫儿,老报错,都是下面这一句惹的祸
Open infor2 & "\" & File2.List(i) For Input As #1
infor4 = Replace(infor4, "\", "")
再试试