0

Two files "test.txt" and "test2.txt" were created in C:\tmp_dir. I want to know how many files in "C:\tmp_dir". My code:

    dim s as string;
    s = System.IO.Directory.GetFiles("C:\tmp_dir");
    LogMessage(s.Length);

But it's obviously wrong. It's returns 40(amount of symbols in path and both files) instead of 2. How can I do this properly?

Mike K
  • 63
  • 1
  • 7

2 Answers2

1

From https://stackoverflow.com/a/15867350/804773 :

dim s as Integer;
s = System.IO.Directory.GetFiles("C:\tmp_dir").Count();
LogMessage(Text(s,"#"));
Grambot
  • 4,370
  • 5
  • 28
  • 43
  • Thanks, but I tried this and it didn't work. "Unknown property: Count". I think it is because of specific scripting in Wonderware Archestra IDE. – Mike K Feb 19 '18 at 04:07
  • Keep in mind, these are just standard .NET library functions you should be able to find ample documentation on MSDN or other resources for .NET. In this case I think `Count` may be a function (not a Property) and would be accessed by `.Count()` as I've edited into my answer – Grambot Feb 20 '18 at 19:10
1

Tanks a lot! As you mentioned "s" must be Integer not string. And with "length" instead of "count" works fine.

dim s as integer;
s = System.IO.Directory.GetFiles("C:\tmp_dir").length;
LogMessage(s);
Mike K
  • 63
  • 1
  • 7