Take a file path from an array of C # files

0

I have an array of files, and I have to get the string from one's route. I can not find any method that does it. The code what it does is go through two directories of files, and then look for the first file of the source directory in the destination directory. This is my code so far, the questions indicate the doubt I have:

 for (int i = 0;i<fileDirOrigenNames.Length;i++ )
 {
      System.IO.Stream[] arrayOrigen = new System.IO.Stream[i];

      for (int j = 0; j <= fileDirDestinoNames.Length; j++)
      {
            System.IO.Stream[] arrayDestino = new System.IO.Stream[i];
            if (arrayOrigen[i].Equals(arrayDestino[j]) == true)
            {
                //???????    mostrarResultadoComparacionPropiedades(arrayOrigen[i].ToString, arrayDestino[j].ToString);
            }
       }
}
    
asked by LopezAi 02.10.2017 в 12:25
source

2 answers

2

Of course the code does not do what you want, although I do not know if I have understood correctly what you are trying to do.

If you want to check if the files of the source route exist in the destination route, here is an example of a method that does it.

This code compares the files only by name, if you want to check the content it would have to complicate something else:

private static void CompararRutas(string origen, string destino)
{
    var sourceDir = new DirectoryInfo(origen);
    var targetDir = new DirectoryInfo(destino);
    var fileDirOrigenNames = sourceDir.GetFiles();
    var fileDirDestinoNames = targetDir.GetFiles();

    foreach (var sourceFile in fileDirOrigenNames)
    {
        var targetFile = fileDirDestinoNames.FirstOrDefault(f => f.Name == sourceFile.Name);
        Debug.WriteLine(
            $"El archivo {sourceFile.Name}{(targetFile == null ? " no" : "")} existe en la ruta destino ({destino})");
    }
}
    
answered by 02.10.2017 / 12:43
source
1

As you're doing, it's okay, the problem is that you're missing the parentheses in ToString :

for (int i = 0;i<fileDirOrigenNames.Length;i++ )
{
  System.IO.Stream[] arrayOrigen = new System.IO.Stream[i];

  for (int j = 0; j <= fileDirDestinoNames.Length; j++)
  {
        System.IO.Stream[] arrayDestino = new System.IO.Stream[i];
        if (arrayOrigen[i].Equals(arrayDestino[j]) == true)
        {
            mostrarResultadoComparacionPropiedades(arrayOrigen[i].ToString(), arrayDestino[j].ToString());
        }
   }
}
    
answered by 02.10.2017 в 12:32