Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 03, 2016, 12:52:33 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: delete files in one folder according to files in another folder  (Read 2596 times)

lijieliang

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
I have some files in one folder and these same files in another folder with a lot more files. How do I delete these files in that folder with a lot more files?
thank you in advance.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: IDEA: delete files in one folder according to files in another folder
« Reply #1 on: November 09, 2009, 07:38:05 PM »
To clarify, you have a list of files in, say, Folder A.  If those same filenames exist in Folder B, you want them deleted.  Is this correct?

lijieliang

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
Re: IDEA: delete files in one folder according to files in another folder
« Reply #2 on: November 09, 2009, 07:42:43 PM »
that's correct.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: IDEA: delete files in one folder according to files in another folder
« Reply #3 on: November 09, 2009, 08:03:06 PM »
Try this (source/binary included):  Download

Code: AutoIt [Select]
  1. ; Set environment.
  2. SetBatchLines, -1
  3. SetControlDelay, -1
  4. DetectHiddenWindows, On
  5. SetWorkingDir, %A_ScriptDir%
  6.  
  7. ; Build main GUI.
  8. GoSub, Gui_Build_Main
  9.  
  10. Return ; End of auto-execute section.
  11.  
  12.  
  13. Gui_Build_Main:
  14. {
  15.     ; Build GUI.
  16.     Gui, Margin, 3, 5
  17.     Gui, Add, Text    , xm     ym    w50  h20 Right 0x200                  , Folder #1:
  18.     Gui, Add, Edit    , xm+55  ym    w270 h20             vFolder_1        ,
  19.     Gui, Add, Button  , xm+330 ym    w30  h20             vBrowse_1 gBrowse, ...
  20.     Gui, Add, Text    , xm     ym+25 w50  h20 Right 0x200                  , Folder #2:
  21.     Gui, Add, Edit    , xm+55  ym+25 w270 h20             vFolder_2        ,
  22.     Gui, Add, Button  , xm+330 ym+25 w30  h20             vBrowse_2 gBrowse, ...
  23.     Gui, Add, Button  , xm+170 ym+53 w190 h25             vDelete   gDelete, &Delete matching files to Recycle Bin
  24.     Gui, Add, Statusbar
  25.         SB_SetText( "Ready.", 1 )
  26.     GUI_ID := WinExist()
  27.     Gui, Show, AutoSize Center, Match & Recycle
  28. }
  29.  
  30.  
  31. GuiEscape:
  32. GuiClose:
  33. {
  34.     ExitApp
  35. }
  36.  
  37.  
  38. Delete:
  39. {
  40.     Gui, 1: Submit, NoHide
  41.  
  42.     ; Basic pre-check.
  43.     If ( Folder_1 = "" OR Folder_2 = "" OR ! FileExist( Folder_1 ) OR ! FileExist( Folder_2 ) )
  44.     {
  45.         MsgBox, 48, Error, Please select valid folders.
  46.         Return
  47.     }
  48.  
  49.     Loop, % Folder_1 . "\*.*", 0, 0
  50.     {
  51.         SB_SetText( "Processing: " . A_LoopFileName, 1 )
  52.  
  53.         If FileExist( Folder_2 . "\" . A_LoopFileName )
  54.         {
  55.             FileRecycle, % Folder_2 . "\" . A_LoopFileName
  56.         }
  57.     }
  58.  
  59.     SB_SetText( "Done.", 1 )
  60. }
  61.  
  62.  
  63. Browse:
  64. {
  65.     Gui, 1: Submit, NoHide
  66.     If ( A_GuiControl = "Browse_1" )
  67.     {
  68.         Folder_1 := ""
  69.         FileSelectFolder, Folder_1, , 2, Select first folder.
  70.         If ( ErrorLevel != 1 )
  71.         {
  72.             GuiControl, Text, Folder_1, % Folder_1
  73.         }
  74.     }
  75.     Else If ( A_GuiControl = "Browse_2" )
  76.     {
  77.         Folder_2 := ""
  78.         FileSelectFolder, Folder_2, , 2, Select second folder.
  79.         If ( ErrorLevel != 1 )
  80.         {
  81.             GuiControl, Text, Folder_2, % Folder_2
  82.         }
  83.     }
  84.     ; Right justify the edit control's content if longer than the control's length
  85.     SendMessage, 0xB1, 500, 500, Edit1 ; 0xB1 is EM_SETSEL
  86.     SendMessage, 0xB1, 500, 500, Edit2 ; 0xB1 is EM_SETSEL
  87. }

lijieliang

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
Re: IDEA: delete files in one folder according to files in another folder
« Reply #4 on: November 09, 2009, 08:06:38 PM »
that does the job. thanks a lot.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: IDEA: delete files in one folder according to files in another folder
« Reply #5 on: November 09, 2009, 08:08:37 PM »
You're welcome.  Happy to help.   :)