Jump to content

Annoying Windows Solution


condoman
 Share

Recommended Posts

$FileListPath = @ScriptDir&"\DeleteFolderList.txt"
AutoItSetOption("TrayIconHide", 1)
#cs
This script helps me deal with the annoying problem of cleaning up temporary folders
and Windows XP will not let you delete it.  My thanks to ezzetabi for inspiring me
with the shell extensions.

Operation:
When a folder will not go away, right click on it and choose Send To Delete Later.
This will append the path into the DeleteFolderList.txt file.  When you next logon,
the Startup folder will run this script and process the entries in the 
DeleteFolderList.txt file moving any folders to the recycle bin.  The DeleteFolderList
file is rewritten with the successful entries removed.  Any lines that
begin with * are comments.  If a folder cannot be removed it will be copied back
to the DeleteFolderList file as a comment.

Optionally you may execute this script with three different command line parameters:
I[nstall] -  will create the needed registry keys, initialize the list file and
    create the Startup shortcut.
U[ninstall] -   will delete everything installed.
E[dit] -  will open notepad on the DeleteFolderList.txt file.

Installation:
1. Copy the executable to a folder of your choice.
2. Execute the DeleteFolder.exe with a parameter of Install

Note:    If you change the name of the executable you must change & recompile the script.
  This script is not bullet proof and only tested on XP.   
#ce

If $CMDLINE[0] <> 0 Then; When a parameter is passed 
    Select
     Case StringLeft(StringUpper($CMDLINE[1]),1) = "D"; when sent from context menu
     $hFileListPath = FileOpen($FileListPath,1)
      FileWriteLine ($hFileListPath,$CMDLINE[2])
     FileClose($hFileListPath)
     Case StringLeft(StringUpper($CMDLINE[1]),1) = "I"; Install reg entry and Startup shortcut
     RegWrite("HKEY_CLASSES_ROOT\Directory\Shell\Annoy1_del_later","","REG_SZ","Send To Delete Later")
     RegWrite("HKEY_CLASSES_ROOT\Directory\Shell\Annoy1_del_later\Command","","REG_SZ",'"'&@ScriptDir&'\DeleteFolder.exe" Delete "%1"')
     $hFileListPath = FileOpen($FileListPath,1); Initialize the list file
      FileWriteLine ($hFileListPath,"* Stick a folder here and it is moved to the recycle bin on next logon")
     FileClose($hFileListPath)
     FileCreateShortcut(@ScriptFullPath, @StartupCommonDir &"\DeleteFolder.lnk")
     MsgBox(0,"Delete Later Utility","Installation Complete")
     Case StringLeft(StringUpper($CMDLINE[1]),1) = "U"; UnInstall what was installed
      RegDelete("HKEY_CLASSES_ROOT\Directory\Shell\Annoy1_del_later")
      FileDelete($FileListPath)
     FileDelete(@StartupCommonDir &"\DeleteFolder.lnk")
     MsgBox(0,"Delete Later Utility","Uninstall Complete")
  Case StringLeft(StringUpper($CMDLINE[1]),1) = "E"; Run Notepad on list file
     Run("notepad "&$FileListPath)
     Case Else
     MsgBox(0,"Delete Later Utility","Unknown Command="&StringUpper($CMDLINE[1]))
    EndSelect
    Exit
EndIf
; When no parameter process the list
$FileWorkPath = _GetFilePath($FileListPath)&_GetFileName($FileListPath)&".tmp"
$hFileWorkPath = FileOpen($FileWorkPath,2)
$hFileListPath = FileOpen($FileListPath,0)
While 1
    $Input = FileReadLine($hFileListPath)
    If @error = -1 Then ExitLoop
    If StringLeft(StringStripWS($Input,3),1) = "*" Then
     FileWriteLine ($hFileWorkPath,$Input)
     ContinueLoop
    EndIf
    If FileRecycle(StringStripWS($Input,3)) <> 1 Then
     FileWriteLine ($hFileWorkPath,"* Unable to delete >"&$Input)
    EndIf        
Wend
FileClose($hFileListPath)
FileClose($hFileWorkPath)
FileMove($FileWorkPath,$FileListPath,1)
Func _GetFilePath ($File)
    $Len = StringLen($File)
    For $iLoop = $Len to 1 Step -1
  If StringMid($File,$iLoop,1)= "\" Then
     ExitLoop
  EndIf
    Next 
    If $iLoop = 0 Then
  Return ""
    Else    
  Return StringMid($File,1,$iLoop)
    EndIf
EndFunc
Func _GetFileName ($File)
    $Len = StringLen($File)
    For $iLoop = $Len to 1 Step -1
  If StringMid($File,$iLoop,1)= "." Then
     ExitLoop
  EndIf
    Next
    If $iLoop <> 0 Then
  $File = StringMid($File,1,$iLoop-1)
  $Len = StringLen($File)
    EndIf
    For $iLoop = $Len to 1 Step -1
  If StringMid($File,$iLoop,1)= "\" Then
     ExitLoop
  EndIf
    Next
    If $iLoop = 0 Then
  Return $File
    Else    
  Return StringTrimLeft($File,$iLoop)
    EndIf
EndFunc
;eof

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...