Error deleting file in Windows Mobile 6.5

0

I'm working on a project for windows mobile 6.5. I am using C # with Compact Framework 3.5 (CF 3.5) and SDK for Windows Mobile 6.5.

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

When you try 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.

Follow 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];
        }
    
asked by anonymous 30.08.2017 / 21:23

1 answer

0

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

Directory.Delete(nomeArq);

by line

File.Delete(nomeArq);

    
05.09.2017 / 21:37