Jump to content
Fórum Script Brasil
  • 0

APAGAR ARQUIVOS TEMPORARIOS POR DATA DE CORTE?


vilmarbr

Question

2 answers to this question

Recommended Posts

  • 0

achei algo..

http://social.msdn.microsoft.com/forums/en...ed-a768f4c26016

private static string logPath = "/DailyLogs/";

private static string logFile = "GTSLog_" + DateTime.Now.ToString("dd_MM_yyyy") + ".txt";

private static void CleanLogFiles()

{

if (DoesLogDirectoryExists())

{

string[] fileNames;

fileNames = Directory.GetFiles(logPath);

foreach (string s in fileNames)

{

DateTime creationDate = File.GetCreationTime(logPath + s);

if (creationDate < DateTime.Now.AddDays(-28))

{

try

{

File.Delete(s);

}

catch (Exception ex)

{

//Do nothing with exception

}

}

}

}

}

Link to comment
Share on other sites

  • 0

Outro esquema melhor....

Private Sub LimparArquivos()

Dim Root As New DirectoryInfo(Page.Request.PhysicalApplicationPath & ConfigurationManager.AppSettings("CaminhoFisicoArquivosTemporarios"))

Dim Files As FileInfo() = Root.GetFiles("*.*")

Dim Filename As FileInfo

For Each Filename In Files

Try

If Filename.CreationTime.AddMinutes(ConfigurationManager.AppSettings("TempoExcArquivo")) < Date.Now Then

Filename.Delete()

End If

Catch erro As Exception

''Ignora erros pois o arquivo pode estar sendo utilizado e a rotina não pode onerar a execução;

Finally

Files = Nothing

Filename = Nothing

End Try

Next

End Sub

--

Web.config

jogar estas chaves:

<add key="CaminhoFisicoArquivosTemporarios" value="ArquivosTemporariosSuaAplicacao\"/>

<add key="TempoExecucaoArquivo" value="10"/><!-- Tempo, em minutos, para a limpeza dos arquivos temporários necessários -->

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...