vilmarbr Posted February 23, 2012 Report Share Posted February 23, 2012 APAGAR ARQUIVOS TEMPORARIOS POR DATA DE CORTE?Como fazer isto ?Preciso apagar todos arquivos, menos os gerados na última meia hora...Grato.Em ASP.NET/VB.NET Quote Link to comment Share on other sites More sharing options...
0 vilmarbr Posted February 23, 2012 Author Report Share Posted February 23, 2012 achei algo..http://social.msdn.microsoft.com/forums/en...ed-a768f4c26016private 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}}}}} Quote Link to comment Share on other sites More sharing options...
0 vilmarbr Posted February 23, 2012 Author Report Share Posted February 23, 2012 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.configjogar estas chaves:<add key="CaminhoFisicoArquivosTemporarios" value="ArquivosTemporariosSuaAplicacao\"/><add key="TempoExecucaoArquivo" value="10"/><!-- Tempo, em minutos, para a limpeza dos arquivos temporários necessários --> Quote Link to comment Share on other sites More sharing options...
Question
vilmarbr
APAGAR ARQUIVOS TEMPORARIOS POR DATA DE CORTE?
Como fazer isto ?
Preciso apagar todos arquivos, menos os gerados na última meia hora...
Grato.
Em ASP.NET/VB.NET
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.