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

Check if file exists

Hi Experts,
I create a row in a table when I receive summary information. Later I receive files with detailed information belonging to the created row.

I need to check if the file is received and if so I need to store the path&filename in the summary row.

The summery row contains a name and a date that can be used to check if the file exists. However the date in the filename will not always be exactly the same. It could be a few days earlier or later.

Can someone point me in the right direction?

Best regards, MB
0
mark_norge
Asked:
mark_norge
  • 2
  • 2
1 Solution
 
DhaestCommented:
Do you want to check for a certain date-range than ?
 Public Function FileExists(ByVal FileFullPath As String) _
      As Boolean
 
        Dim f As New IO.FileInfo(FileFullPath)
        Return f.Exists
 
    End Function
 
    Public Function FolderExists(ByVal FolderPath As String) _
   As Boolean
 
        Dim f As New IO.DirectoryInfo(FolderPath)
        Return f.Exists
 
    End Function

Open in new window

0
 
mark_norgeAuthor Commented:
Thanks for the reply Dhaest,

The date range is in the file name. The file name is for instance:
BRF_Green Concordia_12042009_Some other details.xls (The file name is automatically generated but can be changed)

When I check if the file exists I have Green Concorida (as name) and for instance 10042009 (as date). The name is exactly the same but the date is 2 days less. My problem is how to find a file where I only have part of the filename and regarding the date this has a range.

Regards, MB
0
 
DhaestCommented:
You can't use wildcards with File.Exist, however using the Directory.GetFiles may provide the functionality you are after

string[] files = Directory.GetFiles("D:\Documents and Settings\Lou\My Documents\Visual Studio", "*.txt");
if (files.Length > 0)
{
    // Do something
}

Open in new window

0
 
mark_norgeAuthor Commented:
Thanks a lot, it works.

Private Function ReturnSoundingFileLocation(ByVal Vessel As String, ByVal ReportDateTimeGMT As DateTime) As String
        Dim FileLocation As String = "x"
        Dim Files() As String = Directory.GetFiles("C:\Bunkers\BRF", "*.xls")
        Dim FileDetails() As String
        Dim BunkerDate As DateTime

        If (Files.Length > 0) Then
            For i = 0 To Files.Length - 1
                FileDetails = Files(i).ToString.Split("_"c)
                If FileDetails(1).ToString = Vessel Then
                    BunkerDate = New Date(FileDetails(2).Substring(4, 4), FileDetails(2).Substring(2, 2), FileDetails(2).Substring(0, 2))
                    If BunkerDate > ReportDateTimeGMT.AddDays(-5) And BunkerDate < ReportDateTimeGMT.AddDays(5) Then
                        FileLocation = Files(i).ToString
                    End If
                End If
            Next i
        End If
        Return FileLocation
    End Function
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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