1.

Solve : Is there a way to delete an empty folder??

Answer»

I'm creating a batch file to copy over files. It works well, except when it deletes the old files it leaves empty folders, from copying over empty files. This causes the hard drive to fill up and is not what I WANT to happen.

Is there a command in DOS that will delete the empty folders so this doesn't keep happening?

Realized I needed to clarify. I am copying a shared drive folder from 1 server to another. Both folders are shared and have security settings. I already know about the RMDIR command, but don't want to do that because I will lose all the setting for sharing the folder.

So was wondering if there is a way to delete empty folders with out getting rid of my share/security settings.

ThanksSorry Laxalife, Im confused

You want to delete folders, but not delete them because they would lose their shared settings.


Can you explain what it is that you want to remove ?

Grahamyes you can delete empty folders, you need to open windows expplorer, show all files in folders and then delete the folder then change it back to the old settings.Hey Graham ,

I have a backup folder that is shared, and people can access the folder through IP and logging in. Backup in case main server ever goes down, the content on the backup is up to date and usable.

I need to update the data in the backup folder, but I don't want to RMDIR D:\folder name because I want to keep the sharing and security settings. SO I need to remove the folders and files inside. looks like this:

Backup folder(has sharing and security permissions)
Folder A
Content in A
Folder B
Content in B
Folder C

I need to delete folder A, B, and C, so when I copy over, it doesn't leave any "non-up to date data". I know DOS can remove files...but what about the empty folders that the delete command creates.

In other words, I run the DEL command and I'll be left with Folders A, B, and C with no files/content inside of the folder. I want to know is there any DOS command prompt to delete these empty left over folders?

Hope that helps explain it better.





and b1tch, I'm in the DOS forums. I know how to do it in Windows, I want to do it with a batch file using DOS script.Right, thats a lot clearer(and what I thought it might be)

you can RD or RMDIR the Folder A / B / C

RD "Folder A"

In fact, INSTEAD of deleting the files, do this to remove the lot ! (assumes Backup folder is the current one)

RD /S /Q "Folder A"
RD /S /Q "Folder B"
RD /S /Q "Folder C"
Del /Q *.*

You could of course make it even shorter and more flexible

FOR /D %a in (*.*) DO RD /S /Q "%a"
DEL /Q *.*

which gets rid of everything apart from the shared directory

note .... if you put the above 2 lines into a batch file, you will need to replace both occurrences of % with %%

Good luck
Graham

I figured the 1st way was what I would have to do...which sucks. But I see your 2 line code and I'll use that

Just not 100% sure I understand correctly. I'm not a wiz a DOS, so u think you could explain the 2 line code. Not sure what %a means and how that would limit it to running the command RMDIR for the all the subfolders. Also, how do I define it for the specific folder?

Thanks ALOT Graham. Thats twice you've helped me How do empty folders "fill up" a drive?
when he clarified what he wanted he said he just didn't want to leave all these empty folders in there (im assuming he updates this folder a lot)yes, once i get the batch up and running. It will run everyday. So I would have alot of useless folders in there.Laxalife

You definitely need to know the HELP command
HELP FOR

would tell you that FOR is a looping command, the /D parameter means to only look at directories (without /D, it would look at all files).

Essentially, the %a is a variable that in each iteration of the loop, holds the name of a directory (thats what the *.* means in the brackets, you could limit the search to just Folder* to find any directory whose name starts with Folder.

The DO keyword tells the loop that what follows is a command line to be executed for every iteration, referencing %a means that the directory name can be supplied as a parameter, so each time it would execute the command:
RD /S /Q "%a"

In a batch file, the % symbol is special and you have to 'escape' it by prefixing it with another % symbol.


So assuming your backup folder lives off the root of the C: drive, your batch file would look something like this

Code: [SELECT]@Echo Off
CD /D "C:\Backup folder"
FOR /D %%a in (*.*) DO RD /S /Q "%%a"
DEL /Q *.*
Because the last line deletes all of the files in the backup folder, you wouldnt want the batch file to sit there, so you store it somewhere safe (and out of the way of inquisitive users) and execute it when you need it.

The 2nd line makes sure the backup folder is the current one, so that no accidental unwanted deletions occur (you need to make sure that this drive and path is the correct one for you. The path is in quotes as the folder name contains spaces.

And thats it

Graham
Graham,

Once again, thank you very much for your help.Quote from: Dias de verano on April 16, 2008, 12:56:23 PM

How do empty folders "fill up" a drive?

A folder is allocated to one cluster even when there is no data in the folder. A lot of empty folders adds up to a lot of clusters wasted. This is true in FAT & FAT32 for sure.

I'm not sure how NTFS handles empty folders, but even the empty names would certainly be a nuisance.
Yes I was thinking of NTFS I guess. I had forgotten about FAT32


Discussion

No Comment Found