Store files from a directory in array


I have to store the files of a directory in an array and then traverse that array.

System.IO.DriveInfo dirOrigen = new System.IO.DriveInfo(ruta1);

System.IO.DirectoryInfo dirOrigenInfo = dirOrigen.RootDirectory;

System.IO.FileInfo[] fileDirOrigenNames = dirOrigenInfo.GetFiles("*.*");

for (int i=0;i<fileDirOrigenNames.GetLength;i++ )

At the moment I have this code, I get an error in for with fileDirOrigenNames.GetLength

asked by LopezAi 02.10.2017 в 11:04

1 answer


I guess you're from Java. fileDirOrigenNames is an array of System.IO.FileInfo . To see the size of an array in C # you have two options: the property Length or the GetLength method you need to receive a parameter with the dimension you want to obtain the size . Try this:

for (int i=0;i<fileDirOrigenNames.Length;i++)

or this

for (int i=0;i<fileDirOrigenNames.GetLength(0);i++)
answered by 02.10.2017 / 11:09