0

I have a folder with solidworks parts named A1, A2, A3, A4, A6, A10..... in there. I want to find the first available name in there according to the first available number. In this case it would be A5. What is the best way to do this in vb.net. I found something similar, that maybe could be applied to this problem. Determining the first available value in a list of integers

Marc Kane
  • 13
  • 1

1 Answers1

1

You can do something like this:

Dim dirPath = 'the path of the folder in question...
Dim part = String.
    Concat("A",
            Enumerable.
            Range(1, Directory.GetFiles(dirPath, "A*.sldprt",
                                        SearchOption.TopDirectoryOnly).Count).
                                        DefaultIfEmpty(1).
                                        FirstOrDefault(Function(x) Not File.
                                        Exists(Path.Combine(dirPath, $"A{x}.sldprt"))))