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];
}