Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete empty folders using windows command prompt?

I need to delete all empty folders from my application folder using windows command prompt?

How can I create a bat file like that?

Please help me.

like image 788
DEVOPS Avatar asked Oct 20 '11 04:10

DEVOPS


People also ask

How do I delete empty folders and subfolders in CMD?

Remove empty folders using "for" and "rd" commands. You enumerate and delete all empty folders using CMD internal commands for and rd. This is specific and deletes only the empty ones. Press and hold on the Shift key.

What is the command to delete an empty directory?

Use the rmdir command to remove the directory, specified by the Directory parameter, from the system. The directory must be empty (it can contain only .

Can I delete a folder using CMD?

To delete folders in Windows 10 with CMD you have to use the rmdir command. This command will remove all folders including the subfolders and files in them.


2 Answers

You can use the ROBOCOPY command. It is very simple and can also be used to delete empty folders inside large hierarchy.

ROBOCOPY folder1 folder1 /S /MOVE 

Here both source and destination are folder1, as you only need to delete empty folders, instead of moving other(required) files to different folder. /S option is to skip copying(moving - in the above case) empty folders. It is also faster as the files are moved inside the same drive.

like image 91
Varun Sharma Avatar answered Nov 12 '22 23:11

Varun Sharma


A simpler way is to do xcopy to make a copy of the entire directory structure using /s switch. help for /s says Copies directories and subdirectories except empty ones.

xcopy dirA dirB /S 

where dirA is source with Empty folders. DirB will be the copy without empty folders

like image 20
Dinesh Rajan Avatar answered Nov 12 '22 23:11

Dinesh Rajan