Count files from a certain name into a directory

August 28, 2013 at 12:59:45
Specs: Windows 7
Please, I need a little vbs code to count the files from a certain name (whose name starting by "incrementFile*") which are inside a folder.
For exemple, into my folder, I may have as file names "incrementFile1", "incrementFile2", "incrementFile3", ...and others different names. Please could you help me out? Thank you.

message edited by tamo

See More: Count files from a certain name into a directory

Report •

August 28, 2013 at 19:59:07
Well, this is very roinky, but it worked:
'====== begin vbscript snippet
set ws=createobject("")
set ff=ws.exec("cmd /c dir c:\xxx\incrementfile*|find "" File(s) """)
'target aquired?
wscript.echo c

Report •

August 29, 2013 at 07:59:31
I suppose that's one way to do it. The other is to just count files.

Const nameStart = "incrementFile" : nameLen = Len(nameStart)
Set files = CreateObject("Scripting.FileSystemObject").GetFolder(".").Files
cnt = 0

For Each f in files
  If UCase(Left(f.Name, nameLen)) = UCase(nameStart) Then _
    cnt = cnt + 1
Next 'f

WScript.Echo cnt

How To Ask Questions The Smart Way

Report •

August 30, 2013 at 08:24:57
It's useless to answer this guy's questions.
He rarely picks the best answer.
Only 15% of the time (3 out of 19 questions) has he picked the best answer.

message edited by ksas

Report •
Related Solutions

Ask Question