Sometime Interviewer can ask more questions on File system object related topics, so here i am going to share a very common question that can be ask frequently in any interview.
Ques:How many excel files exists in a particular folder?
Soln.
In below screenshot, we can see that two excel files are exists under the Selenium1 folder.
Execute the Below code that will give you a exact count of excel files in the above folder:
Dim iFileCount, FolderName, vFiles, objFSO
iFileCount = 0
iFileExistCount =0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set FolderName = objFSO.GetFolder("E:\Selenium1") ' Folder Path
Set vFiles =FolderName.Files 'This will create the collection of all files that are exsits under the Selenium1 Folder
For each vFile in vFiles
Print "File Name is "&vFile 'This statement will print the name of all file name one by one
If Instr(1, vFile,"xlsx")>0Then
iFileExistCount = iFileExistCount+1
End If
iFileCount = iFileCount + 1
Next
Print "Excel file Count would be under Selenium1 folder "&iFileExistCount
OutPut:
No comments:
Post a Comment