Micro Focus QTP (UFT) Forums
Find specific file exist in a folder - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Regular Expressions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Regular-Expressions)
+--- Thread: Find specific file exist in a folder (/Thread-Find-specific-file-exist-in-a-folder)



Find specific file exist in a folder - shijukonline - 03-14-2011

Hi,

How I can write a descriptive program to check whether any .mp4 file exist in a particular folder starting with a specific name like 'clip' (eg. clip0019.mp4)

the below code shows clip0019.mp4 exists if the file is in c folder. I want to check any file starting with clip in .mp4 format exist in c: folder

Code:
filespec = "C:\clip0019.mp4"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
MsgBox (msg)

Please help me for this

Thanks in advance.


RE: Find specific file exist in a folder - surya_7mar - 06-07-2011

Code:
sFolderName = "c:\foldername"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(sFolderName) Then
                  Reporter.ReportEvent micWarning, "Unable to Get The Files", "Unable to get the File from the location "&sFolderName&". This may be due to the wrong foldername. Looking for. "
End If
Set fBefore = fso.GetFolder(sFolderName)
Set fcBefore = fBefore.Files
For each fb in fcBefore
       If Left(fb.Name, 4) = "clip" and Right(fb.Name,4) = ".mp4" Then
             print fb.Name
       End If
Next





This will print all the files in a folder where file name starts with "clip" and endd with ".mp4"
This will print all the files in folder where the file name starts with "clip" and ends with ".mp4"

Code:
sFolderName = "c:\foldername"
    
    Set fso = CreateObject("Scripting.FileSystemObject")

    Set fBefore = fso.GetFolder(sFolderName)

    Set fcBefore = fBefore.Files
    
    For each fb in fcBefore
            If Left(fb.Name, 4) = "clip" and Right(fb.Name, 4) = ".mp4" Then
                    print fb.Name
            End If
    Next


THis will print all the files in a folder starts wirh clip and ends with .mp4
Code:
sFolderName = "c:\foldername"
    
    Set fso = CreateObject("Scripting.FileSystemObject")

    Set fBefore = fso.GetFolder(sFolderName)

    Set fcBefore = fBefore.Files
    
    For each fb in fcBefore
            If Left(fb.Name, 4) = "clip" and Right(fb.Name, 4) = ".mp4" Then
                    print fb.Name
            End If
    Next


This will print all the files in folder where the file name starts with "clip" and ends with ".mp4"

Code:
sFolderName = "c:\foldername"

Set fso = CreateObject("Scripting.FileSystemObject")

Set fBefore = fso.GetFolder(sFolderName)

Set fcBefore = fBefore.Files

For each fb in fcBefore
If Left(fb.Name, 4) = "clip" and Right(fb.Name, 4) = ".mp4" Then
print fb.Name
End If
Next


--------------------------------------------------------------------------------