none
variavel no script vbs RRS feed

  • Pergunta

  • Estou precisando trocar a linha 8:  strFolder = "C:\Documents and Settings"
    pela linha:  strFolder ="%HOMEPATH%"

    Mas não funciona quando troco.   Preciso declarar mais alguma coisa ?

    Obrigado

    #############################

    OPTION EXPLICIT
    DIM strExtensionsToDelete,strFolder
    DIM objFSO, MaxAge, IncludeSubFolders
    ' ************************************************************
    ' Setup
    ' ************************************************************
    ' Caminho de pesquisa
    strFolder = "C:\Documents and Settings"
    ' strFolder ="%HOMEPATH%"
    ' Deletar subpastas ?
    includeSubfolders = true
    ' Vírgula para separar as extensões
    strExtensionsToDelete = "mp3,wma"
    ' Arquivos antigos.
    maxAge = 1

    ' ************************************************************

    set objFSO = createobject("Scripting.FileSystemObject")

    DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders


    sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
     DIM objFolder, objSubFolder, objFile
     DIM strExt

     set objFolder = objFSO.GetFolder(strDirectory)
     for each objFile in objFolder.Files
      for each strExt in SPLIT(UCASE(strExtensionsToDelete),",")
       if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
        IF objFile.DateLastModified < (Now - MaxAge) then
         objFile.Delete
         exit for
        END IF
       end if
      next
     next 
     if includeSubFolders = true then ' delete recursivo
      for each objSubFolder in objFolder.SubFolders
       DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge, includeSubFolders
      next
     end if
    end sub


    Aldiko
    segunda-feira, 13 de dezembro de 2010 18:15

Respostas

  • Achei o que eu queria:

    *****************************************

    OPTION EXPLICIT
    DIM strExtensionsToDelete,strFolder,objShell
    DIM objFSO, MaxAge, IncludeSubFolders
    Set objShell = CreateObject("Wscript.Shell")
    ' ************************************************************
    ' Setup
    ' ************************************************************
    ' Caminho de pesquisa
    strFolder = objShell.ExpandEnvironmentStrings("%HOMEPATH%")
    ' Deletar subpastas ?
    includeSubfolders = true
    ' Vírgula para separar as extensões
    strExtensionsToDelete = "mp3,wma"
    ' Arquivos antigos.
    maxAge = 1

    ' ************************************************************

    set objFSO = createobject("Scripting.FileSystemObject")

    DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders


    sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
     DIM objFolder, objSubFolder, objFile
     DIM strExt

     set objFolder = objFSO.GetFolder(strDirectory)
     for each objFile in objFolder.Files
      for each strExt in SPLIT(UCASE(strExtensionsToDelete),",")
       if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
        IF objFile.DateLastModified < (Now - MaxAge) then
         objFile.Delete
         exit for
        END IF
       end if
      next
     next 
     if includeSubFolders = true then ' delete recursivo
      for each objSubFolder in objFolder.SubFolders
       DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge, includeSubFolders
      next
     end if
    end sub


    Aldiko
    • Marcado como Resposta Aldiko segunda-feira, 13 de dezembro de 2010 19:34
    segunda-feira, 13 de dezembro de 2010 19:34