Jump to content
Macro Express Forums

Help with a new Macro - Delete empty folders!


Recommended Posts

Hi maybe someone can help.

i have a folder on my computer which includes at least 30 or so underfolders.

Some of them are empty - some of them includes some files.

 

So i just need a macro with a shortcut which deletes all empty underfolders in the folder

 

seems easy but i really do not know how

 

Thanks

Link to comment
Share on other sites

Hi maybe someone can help.

i have a folder on my computer which includes at least 30 or so underfolders.

Some of them are empty - some of them includes some files.

 

So i just need a macro with a shortcut which deletes all empty underfolders in the folder

 

seems easy but i really do not know how

 

Thanks

 

I've occasionally used one of my programs, called Glary Utilities Pro, to tackle that, although it operates at drive level, not individual folders. But, whatever method you use, be careful about temporarily empty folders that are just awaiting their next contents. If you delete them you'll probably get an error message at some future time when a program automatically tries to save to that folder. At best, it will offer to create it afresh, but it can get messy.

 

BTW, I just ran Glary which found about 300 empty folders on my main HD - but I'm going to pass for now on identifying which ones to zap! ;)

 

Of course, in your case, with only a single folder and only 30 or so subfolders, the issue is more easily controlled. Hopefully someone will come up with an ME Pro macro to do the job. A major snag is that a folder sorted to Size in a Detail view does not show folder size, otherwise you could just group them together and delete them.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Problem is - i get every day some new files in some folders - one day in one folder the other day in a other folder.

All the folders i just move to my usb drive - delete all empty folders in the drive and work with those who have some files in it (updates firmwares and so on)

if i am ready i delete all folders and start the next day with the same procedure.

 

so lets see if someone can create a simple macro - it just have to look at all folders and if the size is 0 it can be deleted.

Seems to be easy but ................... not for me so it is not easy enough :-)))))

Link to comment
Share on other sites

Problem is - i get every day some new files in some folders - one day in one folder the other day in a other folder.

All the folders i just move to my usb drive - delete all empty folders in the drive and work with those who have some files in it (updates firmwares and so on)

if i am ready i delete all folders and start the next day with the same procedure.

 

so lets see if someone can create a simple macro - it just have to look at all folders and if the size is 0 it can be deleted.

Seems to be easy but ................... not for me so it is not easy enough :-)))))

 

I can see a reasonably straightforward way of doing it. I don't have time to write it for you right now, but you should be able to do it in the following steps:

 

1. Open the folder's Properties

2. Use Mouse Move > Relative to Window to click to the right of the Size field. (A text cursor appears.)

3. Copy that to the clipboard and a text variable

4. If the text variable = '0 bytes' close the Properties window and delete the folder, with or without a text message - your call!

5. Otherwise, move down to the next folder

6. Repeat until all folders checked.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

sure this will do - but -

1.

Takes a long time to open every property of the folder

 

2.

repeat - yes - but i have to count befor how many folder are inside - because this also changes every day

 

but i think we are on the right way - just to find a shorter workaround.

 

But thanks first for the help - now i know at least the howto.

Maybe someone else of ISS can give an other hint

Link to comment
Share on other sites

sure this will do - but -

1.

Takes a long time to open every property of the folder

 

? A few milliseconds each? Maybe a tenth of a second for all 30?

 

2.

repeat - yes - but i have to count befor how many folder are inside - because this also changes every day

 

Why do you have to count them? Just step through say 100. Or include logic to test when you get to the end.

 

but i think we are on the right way - just to find a shorter workaround.

 

But thanks first for the help - now i know at least the howto.

Maybe someone else of ISS can give an other hint

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Have you looked at the Repeat with Folder command? Something like this would work:

Repeat with Folder e:\temp\temp // Look for files
 If Variable %Result% Does not Equal ""
Break
 End If
End Repeat

If Variable %Result% Equals ""
 Repeat with Folder e:\temp\temp // Look for folders
If Variable %Result% Does not Equal ""
  Break
End If
 End Repeat
End If

If Variable %Result% Equals ""
 Text Box Display: Empty
Else
 Text Box Display: Not empty
End If

Link to comment
Share on other sites

Another idea: Both XCOPY and ROBOCOPY have the ability to do dry runs (no action taken) and one can direct that to a file. By default if one uses the /S parameter to copy sub-folders it will not copy empty sub-folders. So if you do a dry run and output it to a file you have a nice list of all the folders that are not empty. Now all you need to do is Repeat With Folder recursively and if %Folder Name% does not exist in your ROBOCOPY list it must be empty and you can delete it. To test I would simply read that entire list into a variable and do an If Variable Contains condition. One caveat is that you will want to make sure you don't bump into substrings. What I do is instead of testing %Folder Name% I would compare something like %Folder Name%%CR%LF% to ensure it's the whole text we're matching.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...