• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

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
0
mathieu_cupryk
Asked:
mathieu_cupryk
  • 3
  • 3
1 Solution
 
Un-ObtainiumCommented:
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

0
 
mathieu_cuprykAuthor Commented:
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.
0
 
Un-ObtainiumCommented:
this should work to identify the file names. now you have to compare the date to the current day.
        Dim oFile As New FileInfo(fileName)
        
        If oFile.Extension.ToLower.Equals(".txt") = True Then
            ' Get files that are older then 7 days
            Dim value As String = String.Empty
            If (IsMatch(oFile.Name.ToLower, "^kor_")) = True Then
                value = fileName.Substring(4, 11)
                'Compare dates here
            End If
 
        End If

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mathieu_cuprykAuthor Commented:
Error      1      Name 'IsMatch' is not declared.      C:\svn\scraper_cingular\code\Module1.vb      205      29      ScrapeFilesFromCingular
0
 
mathieu_cuprykAuthor Commented:
Sorry i made a mistake it is Regex
0
 
Un-ObtainiumCommented:
Did this solve your problem?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now