Hi @Gaurav_Gore
Please try this expression:
yourFiles = Directory.GetFiles("C:\YourFolderPath")
.Where(Function(file) Path.GetFileName(file).StartsWith("Entity Changes"))
.Select(Function(file) Path.GetFileName(file))
.ToArray()
The variable yourFiles will be of the data type System.String()
Hope this helps,
Best Regards.
Hi @Gaurav_Gore ,
Could you let us know if you would want to get only one file name or all the list of files present in the folder ? And also do you want the recently created file ?
Hi @Gaurav_Gore ,
If you’re looking to get the latest file from specific folder then you can use below code.
' Specify the directory path
Dim directoryPath As String = "your_directory_path"
' Filter the files by name and extension
Dim files As String() = Directory.GetFiles(directoryPath, "entitychangs*.csv").OrderByDescending(Function(f) New FileInfo(f).CreationTime).ToArray()
' Retrieve the latest file
Dim latestFile As String = files.FirstOrDefault()
' Check if a file matching the criteria was found
If latestFile IsNot Nothing Then
' Get the file name with extension
Dim fileName As String = Path.GetFileName(latestFile)
' Print the latest file name with extension
Console.WriteLine("Latest File: " & fileName)
Else
' Handle the case where no matching file was found
Console.WriteLine("No matching file found.")
End If
You can use above code in invoke code activity or else you can just use assign activity.
Hi @Gaurav_Gore ,
you can add * before and after “entitychangs” to match all the files containing entitychangs as comman name.
Directory.GetFiles(directoryPath, "*entitychangs*.csv").OrderByDescending(Function(f) New FileInfo(f).CreationTime).ToArray()
Hi @Gaurav_Gore
Try the following code -
strLatestFilePath = System.IO.Directory.GetFiles({FolderPath}).AsEnumerable().Where(Function(f) System.IO.Path.GetFileName(f).ToString.StartsWith({SearchString}*)).OrderByDescending(Function(g) System.IO.File.GetCreationTime(g)).First.ToString
Cheers,
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.