Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Excract a string from a file name KOR_20090210115231.TXT

I need everything after the KOR_
just the date and 20090210
and if this is less than the today's date but seven days then add this file to
 Dim reader As New StreamReader(response.GetResponseStream())

            Dim line As String = reader.ReadLine()
            While line IsNot Nothing
                result.Append(line)
                result.Append(vbLf)
                line = reader.ReadLine()
            End While
Avatar of Un-Obtainium
Un-Obtainium
Flag of United States of America image

You can use the following sub to extract the date from your file name assuming the date always follows the "_" .
Imports System.IO
Imports System.Text.RegularExpressions.Regex
 
Private Sub IsDateMatch(ByVal sFileName As String)
        Dim oFile As New FileInfo(sFileName)
        If IsMatch(oFile.Name, "_\d{8}") Then
            MsgBox(Match(oFile.Name, "_\d{8}").ToString)
        End If
 
    End Sub

Open in new window

Avatar of mathieu_cupryk

ASKER

This is what I have
If (Path.GetExtension(filename).Equals(".TXT") Or Path.GetExtension(filename).Equals(".txt")) Then
                    ' Get files that are older then 7 days
                    Dim value As String
                    if (filename contains KOR_ in the 0 to 3 character range ) if this is true
                        value.Substring(4, 11) '' get the date and compare the date and if less older than 7 days deleteftp file
                        ZipOperations.DeleteFTPFile(DeleteFileName, reqFTPIn.Credentials, ConfigurationManager.AppSettings("FTPSite"))
                    End If

                    Continue For
                End If
Maybe u can help me.
ASKER CERTIFIED SOLUTION
Avatar of Un-Obtainium
Un-Obtainium
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Error      1      Name 'IsMatch' is not declared.      C:\svn\scraper_cingular\code\Module1.vb      205      29      ScrapeFilesFromCingular
Sorry i made a mistake it is Regex
Did this solve your problem?