File.Exists (path) returns unexpected result

0

I am new working with C # and I need to know if certain files exist in a directory, which is in the same location as the app. For this I use File.Exists(path) , but in all cases it returns false while the paths of the analyzed files do exist as they are consulted. However first I check if the directory exists with Directory.Exists("audiovisuales\concierto\") to make sure that I am putting the directory path correctly and get true , so I do not know what File.Exists() does not find the files.

This is what I did:

...
using System.IO;

...

while (reader.Read())
{
    Console.WriteLine(reader.GetValue(0) + ";" + reader.GetValue(1) + ";" + reader.GetValue(2) + ";" + reader.GetValue(3));
    String codFilai = (String)reader.GetValue(0);// Ejemplo: codigoFilai = D001
    codFilai = codFilai.ToLower();//codigoFilai = d001, o v007, o c034

    if (codFilai.StartsWith("c"))
    {


        rutaVideo = "audiovisuales\concierto\"+codFilai+".flv'";
        rutaPortada = "audiovisuales\concierto\"+codFilai+".jpg'";
        Console.WriteLine(File.Exists(rutaVideo) ? "Video existe!" : "Video no existe.");
        Console.WriteLine(File.Exists(rutaPortada) ? "Portada existe!" : "Portada no existe.");
        Console.WriteLine(Directory.Exists("audiovisuales\concierto\") ? "Directorio existe!" : "Directorio no existe.");
        Console.WriteLine(rutaVideo);

    }
    else if (codFilai.StartsWith("v"))
    {
        ...
    }
...
    Console.WriteLine("");
}

This is the result returned by the console:

As you can see in the image, in each of the registers it tells me that "the video does not exist" and that the "cover does not exist", but in those routes yes exist those files, as you can see in the following image.

I also tried to add the current path to the string of rutaVideo and rutaPortada in this way:

....
String rutaActual = Directory.GetCurrentDirectory();
...

if (codFilai.StartsWith("c"))
    {


        rutaVideo=rutaActual+"audiovisuales\concierto\"+codFilai+".flv'";
        rutaPortada=rutaActual+"audiovisuales\concierto\"+codFilai+".jpg'";
        Console.WriteLine(File.Exists(rutaVideo) ? "Video existe!" : "Video no existe.");
        Console.WriteLine(File.Exists(rutaPortada) ? "Portada existe!" : "Portada no existe.");
        Console.WriteLine(Directory.Exists("audiovisuales\concierto\") ? "Directorio existe!" : "Directorio no existe.");
        Console.WriteLine(rutaVideo);
...

And I still get the same result.

If the path is correct and the names of the files too, then where am I wrong to not find the files?

    
asked by Adriana Hernández 18.05.2017 в 19:55
source

1 answer

0

Have you tried to remove the " ' " in these two lines?

rutaVideo=rutaActual+"audiovisuales\concierto\"+codFilai+".flv'";
rutaPortada=rutaActual+"audiovisuales\concierto\"+codFilai+".jpg'";

That is:

rutaVideo=rutaActual+"audiovisuales\concierto\"+codFilai+".flv";
rutaPortada=rutaActual+"audiovisuales\concierto\"+codFilai+".jpg";
    
answered by 18.05.2017 / 20:01
source