+ Reply to Thread
Results 1 to 6 of 6

Delete folder and subfolder OKB Files

  1. #1
    Forum Contributor
    Join Date
    02-19-2014
    Location
    NJ
    MS-Off Ver
    Excel 2010
    Posts
    308

    Delete folder and subfolder OKB Files

    Hi ,

    With the below code i can able to delete the Empty Folders/Files from the Directory.But am Struck when i move to the subfolders of the main folders.

    Please Login or Register  to view this content.

    Thanks,
    lax

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,658

    Re: Delete folder and subfolder OKB Files

    Use a coding technique called Recursion where a procedure calls itself for each subfolder. Then if that subfolder has its own subfolders, the procedure calls itself again for each of those. It's not that hard to do. This link explains it well

    Recursion And The FileSystemObject

    You could find several other helpful sites by searching for something like Excel VBA Recursion.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete folder and subfolder OKB Files

    Hello laxmanann,

    This should save you some time. Here is a macro that will recursively remove empty folders in just the main folder or optionally remove all empty folders in the sub folders.

    The argument SearchSubfolders is optional. If this argument is not included in the call, it defaults to False. False will search only the main folder. Setting this argument to True will search all subfolders.

    Macro Code
    Please Login or Register  to view this content.
    Example of calling the Macro
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Contributor
    Join Date
    02-19-2014
    Location
    NJ
    MS-Off Ver
    Excel 2010
    Posts
    308

    Re: Delete folder and subfolder OKB Files

    dear alphafrog,
    Thanks for the help..but with the above code I can able to list out the files present in the folder/directory and I can able to delete the files present in the main folder.but I want to delete all the empty files and folders present in the subfolders of the main folder.pls help me

    Thanx,
    Lax

  5. #5
    Forum Contributor
    Join Date
    02-19-2014
    Location
    NJ
    MS-Off Ver
    Excel 2010
    Posts
    308

    Re: Delete folder and subfolder OKB Files

    Dear Ross,

    Much thanks for the help.@alphafrog .sorry..thanks for the help.actually my reply and Ross 's valueable comment reached in the same time..but my comment reached a seconds late in the post..Thank you ppl again..
    @Ross..how could I thank you man..no words..Searching in google to thank you.but I din get a SPL word other thank you..sorry for tat two dear Ross.

    Thanks,
    Lax

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete folder and subfolder OKB Files

    Hello Lax,

    You're welcome. Glad I could help out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro that searches in folder and subfolder - please help
    By anaconte1010 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2013, 10:11 AM
  2. Create FOLDER / SUBFOLDER from CULUM
    By mash1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-13-2012, 09:29 AM
  3. Macro to Create Folder\Sub Folder\SubFolder\
    By coolhit in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-30-2012, 12:43 PM
  4. Return files from a folder without Subfolder
    By EMoe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2009, 11:33 PM
  5. Selecting a Folder or Subfolder
    By Rabi in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-08-2006, 06:39 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1