Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: elecktra en 27 Julio 2010, 17:13 pm



Título: Ayuda con VBS que borra archivos
Publicado por: elecktra en 27 Julio 2010, 17:13 pm
Estimados como estan?
necesito de su ayuda, hace tiepo em ayudaron con un script de VBS que lo que hace es borrar archivos con 1 mes de antiguedad, este es el codigo:

Código:
set objshell = createobject("wscript.shell")
objshell.run "cmd /c dir C:\pruebas /s /b > temp.txt",vbhide
wscript.sleep 2000
set objfso = createobject("scripting.filesystemobject")
set temp = objfso.opentextfile("temp.txt",1)
do until temp.atendofstream
fi = temp.readline
if objfso.fileexists(fi) = true then
if objfso.getfile(fi).parentfolder.name <> Registros then
if datediff("m",objfso.getfile(fi).datecreated,now()) >= 1 then
objfso.deletefile(objfso.getfile(fi).path)
end if
end if
end if
loop
temp.close

Lo que hace es escanear un directorio y losa rchivos con 1 mes de antiguedad lso elimina, lo que necesito es modificar el tiempo en vez de que sea1 mes necesito que lo elimine en 3 dias, sera posible?
ya que no entiendo VBS.
Gracias.


Título: Re: Ayuda con VBS que borra archivos
Publicado por: Novlucker en 27 Julio 2010, 17:18 pm
Código
  1. set objshell = createobject("wscript.shell")
  2. objshell.run "cmd /c dir C:\pruebas /s /b > temp.txt",vbhide
  3. wscript.sleep 2000
  4. set objfso = createobject("scripting.filesystemobject")
  5. set temp = objfso.opentextfile("temp.txt",1)
  6. do until temp.atendofstream
  7. fi = temp.readline
  8. if objfso.fileexists(fi) = true then
  9. if objfso.getfile(fi).parentfolder.name <> Registros then
  10. if datediff("d",objfso.getfile(fi).datecreated,now()) >= 3 then
  11. objfso.deletefile(objfso.getfile(fi).path)
  12. end if
  13. end if
  14. end if
  15. loop
  16. temp.close
Solo he cambiado la línea 10 :P

Saludos


Título: Re: Ayuda con VBS que borra archivos
Publicado por: elecktra en 27 Julio 2010, 17:33 pm
Se agradece amigo, muchas gracias.