+ Reply to Thread
Results 1 to 33 of 33

Find the Empty Folders -Particular path/Drive

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

    Find the Empty Folders -Particular path/Drive

    Hi all,

    Hope you all doing good.I have a question here.

    I have a 1000 Number of files /Folders /Empty folders in a particular drive or a Particular share point path.How i can find the empty folders alone and delete those empty folders using excel macro.Please help me on the same.


    Thanks,
    Lakshmanan

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find the Empty Folders -Particular path/Drive

    EDITED TO INCLUDE CODE TO DELETE THE EMPTY FOLDERS
    This is the VBA code used to iterate through the folders, list the empty folder paths on the active sheet, and delete the empty folders:
    Please Login or Register  to view this content.
    This code sets the parameters for the above code and runs it
    Please Login or Register  to view this content.
    Is that something you can work with?
    Last edited by Ron Coderre; 06-04-2014 at 09:52 AM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Find the Empty Folders -Particular path/Drive

    Do you really need a macro for that?
    How about this?
    Please make the Post as solved, when you get your answer & Click * if you like my suggestion

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi Ron Coderre ,

    Thanks for the help.But am facing issue when am applying code here.Please refer the attached sheet and help me out..
    Attached Files Attached Files

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

    Re: Find the Empty Folders -Particular path/Drive

    Quote Originally Posted by akhileshgs View Post
    Do you really need a macro for that?
    How about this?

    Hi akhileshgs ,

    Thanks for the reply.But in my organzation this website has been blocked and am not able to acess the site which one you provided.Please if possible upload the file here,
    Expecting positive reply.

    Thanks

  6. #6
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Find the Empty Folders -Particular path/Drive

    RED2.zip
    Hi,
    Here u go

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find the Empty Folders -Particular path/Drive

    ALL of the code I posted should be located in a general module (Module1 in your posted file)...Not a sheet module.

    Also, I made a change in my posted code to delete the empty folders that are found.
    This....
    Please Login or Register  to view this content.
    Should be changed to this:
    Please Login or Register  to view this content.
    Does that help?

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi Ron Coderre ,

    Thanks for the change..But im not able to access my file.May am doing somthing wrong.Please correct me.I have placed the file.In the File name column files names should be listed when click run.After click delete the empty folders should be deleted from the drive.But am sure am doing somthing wrong.Your code is perfect..Thanks..Please correct me.

    In the drive /Share path section i need to put the path name or drive name..Pls help me

    Thanks
    Attached Files Attached Files

  9. #9
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find the Empty Folders -Particular path/Drive

    There is no vba code in the Sheet1 module. Consequently, the 2 buttons have no code to run.

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

    Re: Find the Empty Folders -Particular path/Drive

    That is my proble here.Am trying to to Execute those by putting Codes.But i got confused while placing the code.And i dont know where i place those codes in that modules and sheet modules.Pls help me boss.Am new to Vba and am in learning phase.Pls help me boss.
    What ever am trying it is again and again failing

    Thanks,
    Lakshmanan

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi Ron Coderre,

    Please help me.Am waiting for your reply.Thanks in advance.

    Laksh

  12. #12
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Find the Empty Folders -Particular path/Drive

    Here's an alternative..

    Change the initial filepath (D:\Test\) to suit..

    Please Login or Register  to view this content.

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi Apo,

    Thanks for the response..But i applied the code so many times in the above attached sheet.But am facing problem while running the macro.Please refer the sheet and help me out..

    Laksh

  14. #14
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Find the Empty Folders -Particular path/Drive

    Hi..

    I have a 1000 Number of files /Folders /Empty folders in a particular drive or a Particular share point path.How i can find the empty folders alone and delete those empty folders using excel macro
    What i posted was a method to do just that.. for example.. If you root Dir was "D:\Test\" then the above line of code will delete ALL Folders and Sub Folders that are empty within that Root Dir.

    Isn't that what you want to ultimately do..?

    I don't quite follow why you have got a sheet layout to do this.. unless the reason is something like you want to loop through a list of different Root Directories and remove empty folders/sub folders for each location in the list.??

    To test my code as it is.. create a root Dir (D:\Test\) and place 5 folders in it.
    Add a file to say 3 of those folders.
    Add some subfolders with same kind of thing (some with files.. some without)..

    Note down the folders that are empty.. run that line of code.. and all those Empty folders will be deleted...

  15. #15
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Find the Empty Folders -Particular path/Drive

    Delete file .xlsm
    Hmm.....
    I have added the code for you.

    hope this helps.
    change the path in Module 2 as per your need

    For that, go to developer>>Visual Basics>> You can find the module 2 in the left side.

  16. #16
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Find the Empty Folders -Particular path/Drive

    Hi,
    I just inserted the code given by Ron and did an adition to clear the old list in the list

    Is it possible to add the file path in B3 cell or somewhere instead of doing the hard coding?

    Will be helpful to all of us.
    I tried but failed

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi akhileshgs,

    Thanks for the help..But in my organization every one need to use this tool..So i cant give the access to overwrite the code.My requirement is..First People need to Put the Path of the drive in one cell..then run the code by clicking the button.After click the macro should list the empty files names present in that drive.Then Delete all the files by clicking the Dletle file button.

    Is this possible boss?


    Thanks,
    Lakshmanan
    Quote Originally Posted by akhileshgs View Post
    Attachment 323106
    Hmm.....
    I have added the code for you.

    hope this helps.
    change the path in Module 2 as per your need

    For that, go to developer>>Visual Basics>> You can find the module 2 in the left side.

  18. #18
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Find the Empty Folders -Particular path/Drive

    Why you need 2 buttons to get the list and then to delete it?

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi akhileshgs,

    Thanks..Actually we are doing audit for various projects.Becoz of empty files and non used files our share point drives collapesd many times.For that reason we are sending mail to every team...requesting to delete the empty folders.Each and every one cant go and check every folders of the share point and delte the empty files.So only am requesting you..We need to Put the share point drive path in the excel sheet --> Then click run->The macro should list the empty folders name in the Sheet excel.Then user click the delete button To deltet the empty files from the drive...To esclate the specific team i need a macro to point out the team..So pls help me..waithing for the next version


    Lakshmanan

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

    Re: Find the Empty Folders -Particular path/Drive

    Can any one please help me for this?

  21. #21
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Find the Empty Folders -Particular path/Drive

    I still can't see the point of listing the empty Folders and then deleting them..

    Why not just delete the empty Folders.. that is the ultimate goal isn't it?

    So.. all you need to do is enter you Root Folder path into cell A1 and click the button..

    All Folders that contain NO files within that Root folder path will be deleted...

    Please Login or Register  to view this content.
    Test it on a simple scenario like i posted previously in this thread..

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

    Re: Find the Empty Folders -Particular path/Drive

    Thanks Apo..But i dont know how to place your code and execute..Can you pls pls pls..upload the sample work book which is having your code..Expecting your positive rep,,,i tried and failing all times,,am beginner also

    Laksh

  23. #23
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Find the Empty Folders -Particular path/Drive

    File Attached..

    Just change the string in A1 to the required FolderPath and press the button..

    Like i say.. I would test it on the scenario i outlined in my previous post (first page) to make sure it does what you want..
    Attached Files Attached Files

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi apo,

    Thanks ..You are the boss..But i want one more button to dispaly the empty folder name..First i have to enter the name of the path..Then macro should list the empty folder name list.Then i click another button .Delete the macro should delete the files..I want o show case the file names to project teams..Pls help me..

    Thanks

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

    Re: Find the Empty Folders -Particular path/Drive

    Or is it possible to list the deleted files in the CMD window?or in the same excel sheet?

  26. #26
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Find the Empty Folders -Particular path/Drive

    I am not 100% sure.. but I think this will list all the empty Folders also..

    Again.. I would test this thoroughly before deleting things that might be important..
    Attached Files Attached Files

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi apo,

    Thanks for the help.You are the boss..I tried with my own and it is working perfect..next what i can do?

  28. #28
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Find the Empty Folders -Particular path/Drive

    .next what i can do?
    I am not sure what that relates to.. it's a pretty open ended question.. you could do many things next..

  29. #29
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Find the Empty Folders -Particular path/Drive

    in the mean time, you can change this thread as solved under Thread tools>> Last option
    and
    Add reputation to apo and Ron who helped you


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

    Re: Find the Empty Folders -Particular path/Drive

    Marking this is threaad as solved..But i dont know how to add a reputation for the members who helped me to complete this activity...Thanks lot for the people
    akhileshgs
    Apo
    Ron Coderre

    Thanks macro world heros..C u soon

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

    Re: Find the Empty Folders -Particular path/Drive

    Hi Apo,

    I have modified with my own style.All thing is working fine.But i wanna to refresh the list once deleted the files..For that i need one refresh button to clear the list name when ever i want.or after deleting..

    Laksh
    Attached Files Attached Files

  32. #32
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Find the Empty Folders -Particular path/Drive

    In each reply they made, there will be a star mark and add reputation text on the bottom left side. Click on the star and put your comments

  33. #33
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Find the Empty Folders -Particular path/Drive

    Add an ActiveX CommandButton and add this code to the click Event of it..

    Please Login or Register  to view this content.
    If you're not sure how to add a CommandButton.. just google it.. there's a plethora of tutorials/guides etc ..

+ 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. [SOLVED] Check Properties of folders within drive
    By TonyforVBA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2012, 09:58 AM
  2. Links Error: Remote Path vs T:Drive Path
    By bbarrene in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-11-2010, 11:18 AM
  3. Find File Path to USB Drive
    By andyrads in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-15-2009, 05:32 PM
  4. [SOLVED] Drive - Folders - Files
    By DPC in forum Excel General
    Replies: 1
    Last Post: 05-26-2005, 05:15 PM
  5. [SOLVED] creating folders on hard drive from name field
    By Italian Pete in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-25-2005, 06:48 AM

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