Error while deleting file on Windows Mobile 6.5

Asked

Viewed 37 times

0

I am working on a project for windows mobile 6.5. I am using C# com Compact framework 3.5 (CF 3.5) and the SDK for Windows Mobile 6.5.

My routine records files in a temporary directory for further processing. After a few days the file is renamed and directed to a purge.

While trying to delete the file the following error occurs: Access to the path ' Application Data Volatile Temp 20170822-97703.Nf.env' is denied..

Where:

  • \Application Data Volatile is the default temporary directory Path.GetTempPath()

  • \Temp is my temporary directory diretorioTemp

  • 20170822-97703.Nf.env is the name of my file.

Follows the code used:

const string diretorioTemp = "Temp";

public void ExpurarArquivosEnviados()
        {
            DateTime dataBaseExpugo = new DateTime();
            dataBaseExpugo = DateTime.Now.AddDays(-7);
            var arquivos = BuscarArquivosExpurgo();

            foreach (string nomeArq in arquivos)
            {
                var dataAlteracao = Directory.GetLastWriteTime(nomeArq);
                if (dataAlteracao < dataBaseExpugo)
                {                    
                    Directory.Delete(nomeArq);
                }
            }
        }

private string[] BuscarArquivosExpurgo()
        {
            string searchPattern;
            string diretorioLocal;

            diretorioLocal = Path.GetTempPath();
            diretorioLocal = Path.Combine(diretorioLocal, diretorioTemp);

            if (Directory.Exists(diretorioLocal))
            {
                searchPattern = "*.Env";
                var arquivos = Directory.GetFiles(diretorioLocal, searchPattern);
                return arquivos;
            }
            else
                return new string[0];
        }

1 answer

0


To be able to delete and not occur the access error denied I changed the line

Directory.Delete(nomeArq);

by the line

File.Delete(nomeArq);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.