文件夹名字生成在Comp.txt中
Set ws=WScript.CreateObject("wscript.shell")
w=ws.CurrentDirectory
Set fso=WScript.CreateObject("困岩scripting.filesystemobject")
Set fs=fso.GetFolder(w)
Set f=fs.SubFolders
For Each uu In f
t=t &uu.Name &vbcrlf
Next
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject"李桥)
Set MyFile = fso.CreateTextFile("comp.txt", True)
MyFile.WriteLine(t)
MyFile.Close
MsgBox t
给你写个简单的public function ReplaceStr(FilePath,ExtensioNname,Find,WreplaceStr)on error resume next '绕过读写错误dim fso,read,list set fso = createobject("scripting.filesystemobject") for each list in fso.getfolder(filepath).files '遍历文件夹 if fso.getextensionname(list)=ExtensioNname then '判断文件是否是txt,若是则执行 read=fso.opentextfile(list).readall'读取全文 if instr(read,find)>0 then '如果txt有要替换的关键字则替空碧换,没有就绕过read=replace(read,find,wreplacestr) '替换关键字fso.createtextfile(list.path).write read '写入文本 end if end if next set fso=nothing '释放内存,这里注意,我没有重新设定新对象,尽量不要用斗链举以免你忘记加上close导致代码在读写时发生错误,若一定要用的时候才用,我一般唤斗是这样的end functionreplacestr "e:\1","txt",123,empty'将e:\1文件夹下的所有txt类型文件中的123初始化(即删除) Dim oDLG,iSet oDLG = CreateObject("MSComDlg.CommonDialog")
With oDLG
.DialogTitle = "打开文件"
稿顷 .FilterIndex = 1
'.flags = 512 '设置多选文件选项, 如不需要则删除此行
槐茄 .MaxFileSize = 255
.ShowOpen '选择其他内容:.ShowPrinter,.ShowColor,ShowFont
'.Color=Screen.ActiveForm.ForeColor
'.ShowColor
If .FileName <> "" Then
OpenFileDlg = .FileName
铅敬察 msgbox OpenFileDlg,,"你选择的文件名是:"
i=instrrev(OpenFileDlg,"\")
if i>0 then OpenFileDlg=left(OpenFileDlg,i-1)
msgbox OpenFileDlg,,"你选择的文件夹是:"
End If
End With
Set oDLG = Nothing
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)