Announcement

Collapse
No announcement yet.

Delete Temp Files located in OLK8 folder

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Delete Temp Files located in OLK8 folder

    Does anyone have a script to delete items in the Temporary internet Files\Olk8 folder. I am trying the following but it is not working.

    del *.* %userprofile%\local settings\temporary internet files\olk8b9

    Getting the following error
    The system cannot find the path specified.

    Want to create script and add to users login script or push out via gpo.

  • #2
    Re: Delete Temp Files located in OLK8 folder

    I've been asked if I can do something similar actually last night...

    Except something that'll delete all the temporary internet files from all the profiles on a machine apart from 'Administrator' 'Default User' 'All Users' and other specific profiles.


    As a side note, the OLKx folders change their name - hence you'll probably get can't find folder - e.g. mine is called OLK64F
    due to this you'd either need something that says OLK* or clean up the folder above it:
    C:\Documents and Settings\%user%\Local Settings\Temporary Internet Files


    If you want to delete files on demand for things like the OLK folders you could use something like this;
    (the only problem is for example roaming profiles that append .domain or .000 on the end of userprofiles it won't clean them... so you need to know the foldername of the user not just the username...

    http://forums.petri.com/showthread.php?t=16630

    Code:
    ' 
    ' Note: Files are perminately deleted.
    '       Lifetime = date() - 10 = 10 days
    '       Need Administrive rights on target machine (To access c$ share)
    '	Log File is created on Administrator's machine - c:\logs\target_fileDeleteLog.txt
    '
    
    ' Variables
    
    RemPath = InputBox("Enter Computer Name to clean temporary files from User Profile:", "Temporary Internet Files Cleanup")
    If NOT Left(RemPath,2) = "\\" Then
        RemPath = "\\" & RemPath
    End If
    
    UserAcc = InputBox("Enter the username of the profile to clean:", "Temporary Internet Files Cleanup")
    
    Path = RemPath & "\c$\Documents and Settings\" & UserAcc & "\Local Settings\Temporary Internet Files" 
    
    ' Subfolders to be processed - True/False
    Subfolders = True
    
    ' Length of time to check files for deletion (in days)
    Lifetime = date() - 10 
    
    ' * Change the path to where the log file is.
    ' * Be sure the text file already exists or else 
    ' * script will fail.
    strLogFile = "c:\logs\" & Right(RemPath, Len(RemPath) - 2) & "_fileDeleteLog.txt"
    
    ' Log file creation/check
    strDirectory = "c:\logs"
    strFile = "\" & Right(RemPath, Len(RemPath) - 2) & "_fileDeleteLog.txt"
    
    ' Create the File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    ' Check that the strDirectory folder exists
    If objFSO.FolderExists(strDirectory) Then
       Set objFolder = objFSO.GetFolder(strDirectory)
    Else
    Set objFolder = objFSO.CreateFolder(strDirectory)
    WScript.Echo "Just created " & strDirectory
    End If
    
    If objFSO.FileExists(strDirectory & strFile) Then
    Set objFolder = objFSO.GetFolder(strDirectory)
    Else
    Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
    Wscript.Echo "Just created " & strDirectory & strFile
    End If 
    
    set objFolder = nothing
    set objFile = nothing
    
    If err.number = vbEmpty then
    Set objShell = CreateObject("WScript.Shell")
    ' Open's Log File Directory
    objShell.run ("Explorer" & " " & strDirectory & "\" )
    Else WScript.echo "VBScript Error: " & err.number
    End If
    
    
    ' *******************************************************
    ' Script starts at this point
    ' *******************************************************
    ' Declare a variable as an Array that will store a listing
    ' of files that will be checked.
    
    FilesArray = Array() 
    
    ' Create an instance of the FileSystemObject so that file
    ' information can be obtained.
    
    set fso = createobject("scripting.filesystemobject") 
    
    ' Call the SelectFiles procedure to Fill the array with 
    ' files and folders that will be deleted
    
    SelectFiles path, lifetime, FilesArray, Subfolders
    
    ' Process the FilesArray deleting files as we loop through
    
    numDeleted = 0 
    
    
    for n = 0 to ubound(FilesArray)
        ' Switch off error checking, so that errors are ignored
        strFilePath = FilesArray(n).path 
        on error resume next
        ' Call the delete function to delete the selected file
        FilesArray(n).delete true 
        ' Handle any errors or results.  This could be modified
        '100 to log to a text file.
        if err.number <> 0 then 
            Set objFile = FSO.OpenTextFile(strLogFile, 8) 
            objFile.WriteLine Now & vbTab & "ERROR: " & Err.Number & " " & Err.Dscription & " - Unable to delete: " & strFilePath 
            objFile.Close
        else 
            numDeleted = numDeleted + 1
            Set objFile = FSO.OpenTextFile(strLogFile, 8) 
            objFile.WriteLine Now & vbTab & "Deleted: " & strFilePath 
            objFile.Close
     
        end if 
        ' Switch Error checking back to normal
        on error goto 0 
    next 
    
    Set objFile = FSO.OpenTextFile(strLogFile, 8) 
    objFile.WriteBlankLines(1)
    objFile.WriteLine "Total Files and Folders Deleted: " & numDeleted
    objFile.WriteBlankLines(4)
    objFile.Close
    
    sub SelectFiles(sPath,vlifetime,FilesArrayToKill,bIncludeSubFolders) 
        ' Switch off Error handling, errors ignored.
        on error resume next 
        'select files to delete and add to array... 
        set folder = fso.getfolder(sPath) 
        set files  = folder.files 
    
        ' Loop through files that have been found
        for each file in files 
            ' uses error trapping around access to the 
            ' Date property just to be safe 
            dtlastmodified = null
            on error resume Next 
            dtlastmodified = file.datelastmodified 
            on error goto 0 
    
            if not isnull(dtlastmodified) Then 
                if dtlastmodified < vlifetime then 
                    count = ubound(FilesArrayToKill) + 1 
                    redim preserve FilesArrayToKill(count) 
                    Set FilesArrayToKill(count) = file 
                end if 
            end if 
        next 
    
        ' If sub-folders are selected, call the procedure again to update
        ' the array with the contents.
    
        if bIncludeSubFolders then 
            for each fldr in folder.subfolders 
                SelectFiles fldr.path,vlifetime,FilesArray,true 
            
                ' uses error trapping around access to the 
                ' Date property just to be safe 
                dtlastmodified = null
                on error resume Next 
                dtlastmodified = fldr.datelastmodified 
                on error goto 0 
    
                if not isnull(dtlastmodified) Then 
                    if dtlastmodified < vlifetime then 
                        count = ubound(FilesArrayToKill) + 1 
                        redim preserve FilesArrayToKill(count) 
                        Set FilesArrayToKill(count) = fldr 
                    end if 
                end if 
            next
        end if 
    end sub
    Last edited by Lan; 8th August 2007, 09:47.
    This is my signature.

    Comment


    • #3
      Re: Delete Temp Files located in OLK8 folder

      to check wether the complete path is accessable;
      Click on Start / Run and type:
      "%userprofile%\local settings\temporary internet files\olk8b9"
      and press Enter

      Because that path is not matching the DOS 8.3 naming convention (and it contains spaces) you have to type quotes around the path (or path\file) if you want to use it in a command line.
      In addition; If it happens you have to add quotes within quotes on a command line, in that case the inner quotes must be written like this: \"
      example: runas.exe /user:Administrator "notepad.exe \"%userprofile%\local settings\temporary internet files\olk8b9\error.txt\""

      But if you using the path in a VBScript you must not add extra quotes! (just the ones that should always be around every textstring), except if you run a command line with the 'run' or 'exec' method in the script, then you have to even add more quotes (or use ASCII code: chr(34) ) in the string.

      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X