vbs列出当前脚本所在目录的所有文件名

2020-12-24  本文已影响0人  harv9y
Function ShowFileList(folderspec)

 Dim fso, f, f1,f2,v1,fc, s ,N ,s1 ,s2 ,s3

 Set fso = CreateObject("scripting.FileSystemObject")

 Set f = fso.GetFolder(folderspec)

 Set fc = f.Files

 Set fso = CreateObject("Scripting.FileSystemObject")

 Set MyFile = fso.CreateTextFile("filename.txt", True)
 
 N = 0

 For Each f1 in fc
    
    N = N + 1

    s1 = s& f1.name 

    f2= mid(f1.name,instr(f1.name,"号")+1)

    MyFile.WriteLine(f1.name) 

    s2 = "第 "&N&" 个:"&s1&vbCrLf
    
    s3 = s3+s2

 Next
 
 ShowFileList = "该文件夹中总共 "&N&" 个文件:"&vbCrLf&s3&vbcrlf

End Function

Set ws=WScript.CreateObject("wscript.shell")

w=ws.CurrentDirectory

wenjian=ShowFileList(w)

MsgBox wenjian
上一篇 下一篇

猜你喜欢

热点阅读