0

Tengo un problema y creería que es algo muy tonto, pero llevo ya unos días buscando y probando, pero no me ha funcionado bien

Tengo un programa que al ejecutarse debe eliminar la carpeta de Flash player para que otra aplicación en Flash vuelva a cargar los archivos, el proceso parece que funciona, pero la carpeta no se elimina a pesar de que la barra de progreso de borrado si se ejecuta en pantalla... Tengo que dejarles el código para que sea un poco mas entendible y se pueda revisar.

Soy muy nuevo en C#, así que realmente estoy un poco perdido.


    Process processById = Process.GetProcessById(Interaction.Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8", AppWinStyle.MinimizedFocus, false, -1));
                while (!processById.HasExited)
                {
                    if (!processById.HasExited)
                    {
                        continue;
                    }
                    goto Label0;
                }
            }
            catch (Exception exception)
            {
                ProjectData.SetProjectError(exception);
                ProjectData.ClearProjectError();
            }
        Label0:
            string str = string.Concat(Environment.GetEnvironmentVariable("%appdata%\\Macromedia\\Flash Player"));
            if (MyProject.Computer.FileSystem.DirectoryExists(str))
            {
                try
                {
                    enumerator = MyProject.Computer.FileSystem.GetDirectories(str).GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        string str1 = string.Concat(enumerator.Current, "\\localhost");
                        if (!MyProject.Computer.FileSystem.DirectoryExists(str1))
                        {
                            continue;
                        }
                        using (enumerator1)
                        {
                            enumerator1 = MyProject.Computer.FileSystem.GetDirectories(str1).GetEnumerator();
                            while (enumerator1.MoveNext())
                            {
                                string current = enumerator1.Current;
                                nameOfPath = new string[] { current, "\\", this.GetName_OfPath(Environment.CurrentDirectory), "\\", this.loaderFolderName };
                                string str2 = string.Concat(nameOfPath);
                                if (!MyProject.Computer.FileSystem.DirectoryExists(str2))
                                {
                                    continue;
                                }
                                using (enumerator2)
                                {
                                    enumerator2 = MyProject.Computer.FileSystem.GetFiles(str2).GetEnumerator();
                                    while (enumerator2.MoveNext())
                                    {
                                        string current1 = enumerator2.Current;
                                        string nameOfPath1 = this.GetName_OfPath(current1);
                                        if (!((nameOfPath1.Contains(this.ConstantAKCache) | nameOfPath1.Contains(this.ConstantAKLang)) & nameOfPath1.Contains(this.ExtCacheFiles)))
                                        {
                                            continue;
                                        }
                                        File.Delete(current1);
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    if (enumerator != null)
                    {
                        enumerator.Dispose();
                    }
                }
            }
            str = string.Concat(Environment.GetEnvironmentVariable("ProgramData\\Macromedia\\Flash Player"));
            if (MyProject.Computer.FileSystem.DirectoryExists(str))
            {
                try
                {
                    enumerator3 = MyProject.Computer.FileSystem.GetDirectories(str).GetEnumerator();
                    while (enumerator3.MoveNext())
                    {
                        string str3 = string.Concat(enumerator3.Current, "\\localhost");
                        if (!MyProject.Computer.FileSystem.DirectoryExists(str3))
                        {
                            continue;
                        }
                        using (enumerator4)
                        {
                            enumerator4 = MyProject.Computer.FileSystem.GetDirectories(str3).GetEnumerator();
                            while (enumerator4.MoveNext())
                            {
                                string current2 = enumerator4.Current;
                                nameOfPath = new string[] { current2, "\\", this.GetName_OfPath(Environment.CurrentDirectory), "\\", this.loaderFolderName };
                                string str4 = string.Concat(nameOfPath);
                                if (!MyProject.Computer.FileSystem.DirectoryExists(str4))
                                {
                                    continue;
                                }
                                using (enumerator5)
                                {
                                    enumerator5 = MyProject.Computer.FileSystem.GetFiles(str4).GetEnumerator();
                                    while (enumerator5.MoveNext())
                                    {
                                        string current3 = enumerator5.Current;
                                        string nameOfPath2 = this.GetName_OfPath(current3);
                                        if (!((nameOfPath2.Contains(this.ConstantAKCache) | nameOfPath2.Contains(this.ConstantAKLang)) & nameOfPath2.Contains(this.ExtCacheFiles)))
                                        {
                                            continue;
                                        }
                                        File.Delete(current3);
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    if (enumerator3 != null)
                    {
                        enumerator3.Dispose();
                    }
                }
            }

Gracias de antemano!

2
  • 1
    porque borraste tu pregunta anterior para preguntar exactamente lo mismo, y que se pierda el seguimiento de los comentarios que te hicieron antes?
    – gbianchi
    el 8 may. 2020 a las 17:00
  • Porque era una pregunta diferente a esta, y estaba mal formulada, incluso era un programa diferente
    – Dante
    el 8 may. 2020 a las 19:32

1 respuesta 1

1

Te recomiendo comprobar la ruta del archivo y si este existe puedes hacerlo agregando un:

if(File.Exist(path)){

  console.writeline("si existe"); //este mensaje se imprimirá en la consola.

 //Ahora si vamos a eliminar el archivo/directorio(carpeta)

    Directori.delete(path); //para directorios
    File.delete(path); //para archivos

}
4
  • Y esto entonces debo agregarlo al principio del código supongo no?
    – Dante
    el 8 may. 2020 a las 19:33
  • Debe ir antes del proceso donde el nuevo flash va a cargar los archivos . el 8 may. 2020 a las 19:40
  • Entiendo, aunque creo que no me funcionará :/, solamente debe borrar la carpeta este programa, porque el otro programa que es un juego crea la carpeta nuevamente 😅, que es lo que necesito je
    – Dante
    el 8 may. 2020 a las 19:43
  • Agrega ese codigo y a la variable path agrega la ruta de tu archivo /directorio y listo el 8 may. 2020 a las 19:51

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.