DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

lijieliang

  • Participant
  • Joined in 2009
  • *
  • Posts: 3
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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: IDEA: delete files in one folder according to files in another folder
« Reply #1 on: November 10, 2009, 01:38 AM »
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
  • *
  • Posts: 3
Re: IDEA: delete files in one folder according to files in another folder
« Reply #2 on: November 10, 2009, 01:42 AM »
that's correct.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: IDEA: delete files in one folder according to files in another folder
« Reply #3 on: November 10, 2009, 02:03 AM »
Try this (source/binary included):  Download

Code: (autoit)
; Set environment.
SetBatchLines, -1
SetControlDelay, -1
DetectHiddenWindows, On
SetWorkingDir, %A_ScriptDir%

; Build main GUI.
GoSub, Gui_Build_Main

Return ; End of auto-execute section.


Gui_Build_Main:
{
    ; Build GUI.
    Gui, Margin, 3, 5
    Gui, Add, Text    , xm     ym    w50  h20 Right 0x200                  , Folder #1:
    Gui, Add, Edit    , xm+55  ym    w270 h20             vFolder_1        ,
    Gui, Add, Button  , xm+330 ym    w30  h20             vBrowse_1 gBrowse, ...
    Gui, Add, Text    , xm     ym+25 w50  h20 Right 0x200                  , Folder #2:
    Gui, Add, Edit    , xm+55  ym+25 w270 h20             vFolder_2        ,
    Gui, Add, Button  , xm+330 ym+25 w30  h20             vBrowse_2 gBrowse, ...
    Gui, Add, Button  , xm+170 ym+53 w190 h25             vDelete   gDelete, &Delete matching files to Recycle Bin
    Gui, Add, Statusbar
        SB_SetText( "Ready.", 1 )
    GUI_ID := WinExist()
    Gui, Show, AutoSize Center, Match & Recycle
}
Return


GuiEscape:
GuiClose:
{
    ExitApp
}
Return


Delete:
{
    Gui, 1: Submit, NoHide

    ; Basic pre-check.
    If ( Folder_1 = "" OR Folder_2 = "" OR ! FileExist( Folder_1 ) OR ! FileExist( Folder_2 ) )
    {
        MsgBox, 48, Error, Please select valid folders.
        Return
    }

    Loop, % Folder_1 . "\*.*", 0, 0
    {
        SB_SetText( "Processing: " . A_LoopFileName, 1 )

        If FileExist( Folder_2 . "\" . A_LoopFileName )
        {
            FileRecycle, % Folder_2 . "\" . A_LoopFileName
        }
    }

    SB_SetText( "Done.", 1 )
}
Return


Browse:
{
    Gui, 1: Submit, NoHide
    If ( A_GuiControl = "Browse_1" )
    {
        Folder_1 := ""
        FileSelectFolder, Folder_1, , 2, Select first folder.
        If ( ErrorLevel != 1 )
        {
            GuiControl, Text, Folder_1, % Folder_1
        }
    }
    Else If ( A_GuiControl = "Browse_2" )
    {
        Folder_2 := ""
        FileSelectFolder, Folder_2, , 2, Select second folder.
        If ( ErrorLevel != 1 )
        {
            GuiControl, Text, Folder_2, % Folder_2
        }
    }
    ; Right justify the edit control's content if longer than the control's length
    SendMessage, 0xB1, 500, 500, Edit1 ; 0xB1 is EM_SETSEL
    SendMessage, 0xB1, 500, 500, Edit2 ; 0xB1 is EM_SETSEL
}
Return

lijieliang

  • Participant
  • Joined in 2009
  • *
  • Posts: 3
Re: IDEA: delete files in one folder according to files in another folder
« Reply #4 on: November 10, 2009, 02:06 AM »
that does the job. thanks a lot.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: IDEA: delete files in one folder according to files in another folder
« Reply #5 on: November 10, 2009, 02:08 AM »
You're welcome.  Happy to help.  :)

Original address: https://www.donationcoder.com/forum/index.php?topic=20568.0