Dim fso
Set fso = CreateObject("scripting.filesystemobject")
vbfilecount=0
xlsxfilecount=0
txtfilecount=0
Set ofolder=fso.GetFolder("C:\Users\sunshine\Desktop\vbscriptprgm\SeparateFiles by Extension\")
set filecol=ofolder.Files
Print "Total files are: "&filecol.Count
For each filename in filecol
Print filename.Name
fullname=filename.Name
If instr(1,fullname,".vbs")>0 Then
vbfilecount=vbfilecount+1
ElseIf instr(1,fullname,".xlsx")>0 Then
xlsxfilecount=xlsxfilecount+1
ElseIf instr(1,fullname,".txt")>0 Then
txtfilecount=txtfilecount+1
End If
Next
Print "vbfilecount is "&vbfilecount
Print "xlsxfilecount is "&xlsxfilecount
Print "txtfilecount is "&txtfilecount
Set fso=nothing
------Output-------------------------
Total files are: 6
BlankFile.vbs
New Microsoft Office Excel Worksheet.xlsx
New Text Document (2).txt
New Text Document.txt
test.txt
xlfile.xlsx
vbfilecount is 1
xlsxfilecount is 2
txtfilecount is 3
No comments:
Post a Comment