October 5, 2015 at 12:36 pm
Hi,
I need to pick a latest file from folder.Can you please help with the below code where I need to add the logic to pick latest file.
Dim sTimeStamp As String = CStr(Format(Now(), "yyyyMMdd"))
Dim Sup_file_name_pgp As String = ""
Dim Sup_file_name_txt As String = ""
Dim sSuppFilePatern As String = Dts.Variables("Supp_File_Patern").Value.ToString
Dim Sup_Source_file_path As String = Dts.Variables("Suppress_Source_File_Path").Value.ToString
Dim Sup_desti_file_path As String
Dim Suppress_Source_Filename_To_Decrypt As String
Dim Suppress_Desti_Filename_To_Decrypt As String
Dim File_Name As New DirectoryInfo(Sup_Source_file_path.ToString)
Dim Files As FileInfo() = File_Name.GetFiles(sSuppFilePatern)
Dim Fil As FileInfo
Dim lastModified As DateTime = DateTime.MinValue
For Each Fil In Files
If My.Computer.FileSystem.FileExists(Sup_Source_file_path.ToString & "\Archive\" & Fil.Name.ToString()) Then
Else
Sup_file_name_pgp = Fil.Name.ToString()
MsgBox("Else Part :" & Sup_file_name_pgp.ToString)
End If
Next
'Sup_file_name_pgp = "sup_visalist_20101004.txt.pgp"
'Sup_file_name_pgp = "sup_visalist_" & sTimeStamp & ".txt.pgp"
'Sup_file_name_pgp = "sup_visalist_" & sTimeStamp & ".dat.pgp"
Dts.Variables("Suppress_File_Name_pgp").Value = CStr(Sup_file_name_pgp)
'MsgBox(Len(Dts.Variables("Suppress_File_Name_pgp").Value.ToString).ToString)
Sup_Source_file_path = CStr(Dts.Variables("Suppress_Source_File_Path").Value)
Sup_desti_file_path = CStr(Dts.Variables("Suppress_Desti_File_Path").Value)
'MsgBox(Sup_Source_file_path)
'MsgBox(Sup_desti_file_path)
Suppress_Source_Filename_To_Decrypt = CStr(Sup_Source_file_path & "\" & Sup_file_name_pgp)
MsgBox(Suppress_Source_Filename_To_Decrypt.ToString)
Dts.Variables("Suppress_Source_Filename_To_Decrypt").Value = Suppress_Source_Filename_To_Decrypt
'MsgBox(Suppress_Source_Filename_To_Decrypt.ToString)
If Sup_file_name_pgp.LastIndexOf(".") > 0 Then
Sup_file_name_txt = Sup_file_name_pgp.Substring(0, Sup_file_name_pgp.LastIndexOf("."))
MsgBox(Sup_file_name_txt)
End If
'MsgBox(Sup_file_name_txt)
'Sup_file_name_txt = "sup_visalist_" & sTimeStamp & ".dat"
'Sup_file_name_txt = "sup_visalist_" & sTimeStamp & ".dat"
Dts.Variables("Suppress_File_Name_txt").Value = Sup_file_name_txt
Suppress_Desti_Filename_To_Decrypt = CStr(Sup_desti_file_path & Sup_file_name_txt)
Dts.Variables("Suppress_Desti_Filename_To_Decrypt").Value = Suppress_Desti_Filename_To_Decrypt
MsgBox(Suppress_Desti_Filename_To_Decrypt)
If My.Computer.FileSystem.FileExists(Suppress_Source_Filename_To_Decrypt) Then
Dts.Variables("New_Sup_Files").Value = 1
MsgBox("Inside Loop")
Else
Dts.Variables("New_Sup_Files").Value = 0
MsgBox("Outside Loop")
End If
I know that I need to add logic in For Loop but, I am not able to work it out.
Thanks In advance.
October 6, 2015 at 9:40 am
Hi guys,
Below is the code I have used to pick the latest file from folder and I am able to work it out.
ElseIf Fil.LastWriteTime > lastModified Then
lastModified = Fil.LastWriteTime
Suppress_Source_Filename_To_Decrypt = Fil.Name.ToString()
Sup_file_name_pgp = Suppress_Source_Filename_To_Decrypt.ToString()
Thanks,
October 6, 2015 at 4:51 pm
Glad you got it to work. I saw your post late yesterday, but didn't have time to answer it. I've also made the jump from VB to C# this year so going back and looking at VB code takes more time! Again, glad you figured it out and thanks for posting your solution to help others out.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy