I am trying to determine the latest file in a folder and it fails in NX but not as general vb.net program. What am I missing?
Option Strict Off
Imports System
Imports NXOpen
Imports System.Diagnostics
Module NXJournal
Sub Main ' (ByVal args() As String)
Dim dir = New System.IO.DirectoryInfo("c:\100")
Dim file = dir.EnumerateFiles("*.cls").
OrderByDescending(Function(f) f.LastWriteTime).
FirstOrDefault()
If file IsNot Nothing Then
Dim path = file.FullName
'' etc..
msgbox(path)
End If
Console.WriteLine("path=")
End Sub
End Module
Here is the error message I get in NX12:
=============================
System.MissingMemberException: Public member ‘OrderByDescending’ on type ‘FileSystemEnumerablelterator(Of
Filelnfo)’ not found.
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(StringMemberName, Boolean ReportErrors)
at MicrosoftVisualBasic.CompilerServices.NewLateßinding.QbjectLateGet(Object Instance, Type Type, String
MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at MicrosoftVisua I Basic.CompilerServices.NewLateBindingLateGet((Object Instance, Type Type, String MemberName,
Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at NXiournal.Main() in C:\Users\USERID1\AppData\Local\Temp\2\NXJournaIs564\journalO.vb:Iine 10
================================
re: find latest file
I believe that the "order by" functions are part of the Linq namespace. If you are running your code as a journal (tools -> journal -> play), your code cannot make use of the Linq functions. In this case, I'd suggest writing your own sort function. One example can be found here:
http://nxjournaling.com/content/sort-list-nx-objects
If you do have an author license, you can add a reference to the Linq library and use the functions as you need.