Jamie
Jamie

Reputation: 105

FileSystemInfo to string array

I would like to know what the most efficient way of converting a FileSystemInfo to a string array is - My code as is follows:

    string[] filePaths;
    DirectoryInfo di = new DirectoryInfo(batchDirectory);
    FileSystemInfo[] files = di.GetFileSystemInfos();
    filePaths = files.OrderBy(f => f.CreationTime); 

I tried:

filePaths = files.OrderBy(f => f.CreationTime).ToArray; 

but had no luck

Upvotes: 0

Views: 576

Answers (2)

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28990

Add parenthesis () to Array;

 files.OrderBy(f => f.CreationTime).ToArray();

Upvotes: 0

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174349

Try this:

filePaths = files.OrderBy(f => f.CreationTime).Select(x => x.FullName).ToArray(); 

Upvotes: 3

Related Questions