Results 1 to 11 of 11

Thread: delete folders on search

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    First step is to delete all folders of Size 0
    Recursion is your friend

    Declare objFSO at module level, so the same FSO can be used by all recursions. Set obFSO in the main sub. In the main sub, call the Function described below, passing the root Folder

    Build a Function that will take one Folder, IF it's size is 0 then
    Delete it
    exit Function.
    Declare all needed Variables, Except obFSO, inside the function.
    Else create a list of sub folders,
    for each subfolder, call itself, passing the subfolder
    Next SubFolder
    End IF
    End Function

    That is a nice simple recursive function that should run thru 500 subfolders in 1 or 2 minutes while being a good example of recursiveness,

    As for moving files: At first thought, I would use a Module level Dictionary to keep a list of files that are where they should be, A recursive function can use an outside non recursive function to manipulate the Dictionary for each File. The Dictionary can keep the LastModifiedDate as an Item so you can keep the latest file.Actually, I would use 2 outside functions, 1 to check the dictionary (Delete file if True) and 1 to update it (Continue if True). Both should return Booleans
    Last edited by SamT; 06-23-2021 at 09:50 PM.
    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •