check a block of files in dir

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

check a block of files in dir

Post by sal21 »

....
501-L0_04-03-2013
502-L0_04-03-2013
504-L0_04-03-2013
505-L0_04-03-2013
501-L0_06-03-2013
502-L0_06-03-2013
504-L0_06-03-2013
505-L0_06-03-2013
...
I have in a c:\dir1\ the txt files in list.

based 50X-L0_ and date is possible if the "poker" ( :grin: )of file are exactlly a block of for????

501-L0_06-03-2013
502-L0_06-03-2013
504-L0_06-03-2013
505-L0_06-03-2013

this poker of file is ok

501-L0_06-03-2013
502-L0_06-03-2013
505-L0_06-03-2013

This is a tris not a poker of file.... the file 504-L0_06-03-2013 not present in poker

User avatar
HansV
Administrator
Posts: 78628
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: check a block of files in dir

Post by HansV »

Does this do what you want? You'll have to complete the code yourself.

Code: Select all

Sub CheckBlock()
    Dim strPrefix As String
    Dim dtmDate As Date
    Dim strDate As String
    Dim strFolder As String
    Dim strFile As String
    Dim lngCount As Long

    strFolder = "C:\Dir1\"
    strPrefix = "50?-L0_"
    dtmDate = Date ' or DateSerial(2013,3,4) or ...
    strDate = Format(dtmDate, "dd\-mm\-yyyy")

    strFile = Dir(strFolder & strPrefix & strDate & ".txt")
    Do While strFile <> ""
        lngCount = lngCount + 1
        strFile = Dir
    Loop
    If lngCount = 4 Then
        ' We have 4 files matching the pattern
    Else
        ' We have a different number
    End If
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: check a block of files in dir

Post by sal21 »

HansV wrote:Does this do what you want? You'll have to complete the code yourself.

Code: Select all

Sub CheckBlock()
    Dim strPrefix As String
    Dim dtmDate As Date
    Dim strDate As String
    Dim strFolder As String
    Dim strFile As String
    Dim lngCount As Long

    strFolder = "C:\Dir1\"
    strPrefix = "50?-L0_"
    dtmDate = Date ' or DateSerial(2013,3,4) or ...
    strDate = Format(dtmDate, "dd\-mm\-yyyy")

    strFile = Dir(strFolder & strPrefix & strDate & ".txt")
    Do While strFile <> ""
        lngCount = lngCount + 1
        strFile = Dir
    Loop
    If lngCount = 4 Then
        ' We have 4 files matching the pattern
    Else
        ' We have a different number
    End If
End Sub
are you a magician? :grin: :thankyou: :thankyou: :thankyou: :clapping:

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: check a block of files in dir

Post by sal21 »

HansV wrote:Does this do what you want? You'll have to complete the code yourself.

Code: Select all

Sub CheckBlock()
    Dim strPrefix As String
    Dim dtmDate As Date
    Dim strDate As String
    Dim strFolder As String
    Dim strFile As String
    Dim lngCount As Long

    strFolder = "C:\Dir1\"
    strPrefix = "50?-L0_"
    dtmDate = Date ' or DateSerial(2013,3,4) or ...
    strDate = Format(dtmDate, "dd\-mm\-yyyy")

    strFile = Dir(strFolder & strPrefix & strDate & ".txt")
    Do While strFile <> ""
        lngCount = lngCount + 1
        strFile = Dir
    Loop
    If lngCount = 4 Then
        ' We have 4 files matching the pattern
    Else
        ' We have a different number
    End If
End Sub
to understand ? is similar the *, or not?

User avatar
HansV
Administrator
Posts: 78628
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: check a block of files in dir

Post by HansV »

? stands for a single character, * for any number of characters.

So "S?l" matches "Sal" and "Sol" and "Sql", but not "Sail", nor "Strudel".
On the other hand, "S*l" matches "Sal" and "Sail" and "Sl" and "S456l".
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: check a block of files in dir

Post by sal21 »

HansV wrote:? stands for a single character, * for any number of characters.

So "S?l" matches "Sal" and "Sol" and "Sql", but not "Sail", nor "Strudel".
On the other hand, "S*l" matches "Sal" and "Sail" and "Sl" and "S456l".
NICE EXPLAIN... TKS. :thankyou: :thankyou: