Usuário com melhor resposta
criar limpador de disco

Pergunta
-
Ola eu queria criar uma aplicação para fazer limpeza do disco de arquivos inuteis
Exemplo:
Arquivos temporarios; Historico da web; ficheiros cache; ficheiros reciclagem; ficheiros hibernação; entre outros
Como posso fazer? Primeiro preciso dos diretorios cero?
Ja agora eu uso o Visual Studio 2010Profissional
- Movido AndreAlvesLimaModerator quarta-feira, 28 de dezembro de 2011 11:24 (De:Visual Studio - Geral)
Respostas
-
Ola Fabio, você poderia navegar pelos arquivos de uma pasta e executar um Delete, tem um exemplo muito bom da MS:
string sourceDir = @"c:\current"; string backupDir = @"c:\archives\2008"; try { string[] picList = Directory.GetFiles(sourceDir, "*.jpg"); string[] txtList = Directory.GetFiles(sourceDir, "*.txt"); // Copy picture files. foreach (string f in picList) { // Remove path from the file name. string fName = f.Substring(sourceDir.Length + 1); // Use the Path.Combine method to safely append the file name to the path. // Will overwrite if the destination file already exists. File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), true); } // Copy text files. foreach (string f in txtList) { // Remove path from the file name. string fName = f.Substring(sourceDir.Length + 1); try { // Will not overwrite if the destination file already exists. File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName)); } // Catch exception if the file was already copied. catch (IOException copyError) { Console.WriteLine(copyError.Message); } } // Delete source files that were copied. foreach (string f in txtList) { File.Delete(f); } foreach (string f in picList) { File.Delete(f); } } catch (DirectoryNotFoundException dirNotFound) { Console.WriteLine(dirNotFound.Message); }
http://msdn.microsoft.com/en-us/library/system.io.file.delete.aspx
Rodrigo Reis Ferreira
Microsoft Certified- Sugerido como Resposta Rodrigo Reis Ferreira quinta-feira, 1 de dezembro de 2011 10:39
- Marcado como Resposta AndreAlvesLimaModerator quinta-feira, 12 de janeiro de 2012 21:19
Todas as Respostas
-
Ola Fabio, você poderia navegar pelos arquivos de uma pasta e executar um Delete, tem um exemplo muito bom da MS:
string sourceDir = @"c:\current"; string backupDir = @"c:\archives\2008"; try { string[] picList = Directory.GetFiles(sourceDir, "*.jpg"); string[] txtList = Directory.GetFiles(sourceDir, "*.txt"); // Copy picture files. foreach (string f in picList) { // Remove path from the file name. string fName = f.Substring(sourceDir.Length + 1); // Use the Path.Combine method to safely append the file name to the path. // Will overwrite if the destination file already exists. File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), true); } // Copy text files. foreach (string f in txtList) { // Remove path from the file name. string fName = f.Substring(sourceDir.Length + 1); try { // Will not overwrite if the destination file already exists. File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName)); } // Catch exception if the file was already copied. catch (IOException copyError) { Console.WriteLine(copyError.Message); } } // Delete source files that were copied. foreach (string f in txtList) { File.Delete(f); } foreach (string f in picList) { File.Delete(f); } } catch (DirectoryNotFoundException dirNotFound) { Console.WriteLine(dirNotFound.Message); }
http://msdn.microsoft.com/en-us/library/system.io.file.delete.aspx
Rodrigo Reis Ferreira
Microsoft Certified- Sugerido como Resposta Rodrigo Reis Ferreira quinta-feira, 1 de dezembro de 2011 10:39
- Marcado como Resposta AndreAlvesLimaModerator quinta-feira, 12 de janeiro de 2012 21:19
-
-
-
-
Fabio,
Conseguiu solucionar essa sua questao?
André Alves de Lima
Microsoft MVP - Client App Dev
Visite o meu site: http://www.andrealveslima.com.br
Me siga no Twitter: @andrealveslima -
Prezado(a),Estou migrando seu post para o fórum de Windows Forms.Por favor, das próximas vezes que tiver alguma dúvida relacionada a esse assunto, poste por lá.Obrigado.
André Alves de Lima
Microsoft MVP - Client App Dev
Visite o meu site: http://www.andrealveslima.com.br
Me siga no Twitter: @andrealveslima