To find empty directories in Windows, by using the Command Prompt, we can use the following command,
1 |
DIR /AD/B/S | SORT /R |
- This command will search for all directories (
/ad
for current dir) in the current directory and its subdirectories (/s
for subdir) - Display their names (
/b
). Thefindstr
the command is used to filter the output and only show directories (denoted by the “:” pattern).
Note that this command will only show directories that are completely empty (i.e., they do not contain any files or subdirectories).
If we want to include directories that contain empty subdirectories, we can use the following command instead,
1 |
dir /s /b /ad /s | findstr ":\" |
The above command will search for all directories in the current directory with its subdirectories.
Locate empty directories in windows and store the command
To save the list of empty directories to a text file, we can redirect the output of the command to a text file using the >
operator, like this,
1 |
dir /s /b /ad | findstr ":\" > empty_dirs.txt |
This will save the list of empty directories to a text file called empty_dirs.txt
in the current directory.
We can also specify a specific directory to search for empty directories by replacing .
with the path to the directory, like this:
1 |
dir /s /b /ad "C:\my_directory" | findstr ":\" > empty_dirs.txt |
The above command will search for empty directories in the C:\my_directory
directory and save the results to the empty_dirs.txt
file.
Also Read:
- PHP: Logout From All Devices on Password Change
- Send Emails in JavaScript Using SMTP with Example
- How to check if an array is empty, NULL, or undefined in jQuery?