文件夹名字生成在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
获取自身文件名的——Dim fso,f
Set fso = CreateObject("Scripting.FileSystemObject")
f = fso.GetFile(Wscript.scriptfullname).name
--------------------------------------------------
获取自身完整路径的
Dim fso,f
Set fso = CreateObject("Scripting.FileSystemObject")
f = fso.GetFile(Wscript.scriptfullname).path
给你写个简单的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初始化(即删除)欢迎分享,转载请注明来源:内存溢出
评论列表(0条)