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
- \ Temp is my temporary directory
diretorioTemp
- 20170822-97703.Nf.env is the name of my file.
Path.GetTempPath()
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];
}