Mark Bakelaar
asked on
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
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:\Bun kers\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).Substr ing(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
Private Function ReturnSoundingFileLocation
Dim FileLocation As String = "x"
Dim Files() As String = Directory.GetFiles("C:\Bun
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("_
If FileDetails(1).ToString = Vessel Then
BunkerDate = New Date(FileDetails(2).Substr
If BunkerDate > ReportDateTimeGMT.AddDays(
FileLocation = Files(i).ToString
End If
End If
Next i
End If
Return FileLocation
End Function
Open in new window