We help IT Professionals succeed at work.

Excract a string from a file name KOR_20090210115231.TXT

mathieu_cupryk
on
Medium Priority
236 Views
Last Modified: 2012-05-06
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
Comment
Watch Question

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

Author

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.
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Error      1      Name 'IsMatch' is not declared.      C:\svn\scraper_cingular\code\Module1.vb      205      29      ScrapeFilesFromCingular

Author

Commented:
Sorry i made a mistake it is Regex
Did this solve your problem?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.