How to list all files inside folder without **foreach**

I have a simple structure of folder it so simple like this
Folder
β€”> TEST
and the folder i had just 3 files inside image at below

image

so i know how to list all file inside target folder and get only filenames by using Directory.GetFiles or Path.GetFile

simple function should be like this

so the result will be like this
image

or if i want to show only filename i will do something like this
image

then result will be like this
image

Anyone can show me how to list all files inside folder without foreach
So, i need something easy to debug in console it very simple like…

A1.txt, A2.txt, A3.txt

HI @lovepong66

Try this Expression

String.Join(",",Directory.GetFiles("Your path"))

Regards
Sudharsan

Adding to this Checkout this Expression

String.Join(",",Directory.GetFiles(Environment.CurrentDirectory).AsEnumerable().Select(Function(s) Path.GetFileName(s.ToString)).ToArray)


image

Hope this Helps

Regards
Sudharsan

2 Likes

@lovepong66

In Your Case you can try this

String.Join(",",Directory.GetFiles("Your Path","*.txt").AsEnumerable().Select(Function(s) Path.GetFileName(s.ToString)).ToArray)

Regards
Sudharsan

Nice!!! That what i think. Thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.