K
K
Kamil2021-12-07 12:46:34
cmd/bat
Kamil, 2021-12-07 12:46:34

How to delete bulk folders weighing less than 1mb?

Please tell me, there is a folder in which there are thousands of folders.
I need to delete folders in this folder that weigh less than 1 megabyte . I saw solutions on the Internet, but there is
only deleting files, not the whole folder (If it weighs less ...)

, with file deletion

@Echo Off
SetLocal EnableExtensions

Set Fldr=Z:\SomeFolder
For /R %Fldr% %%I In (*.*) Do If %%~zI LSS 1024 Del /F /Q "%%~I"

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Damian Lewis, 2021-12-07
@Lakika

Let's not complicate everything with the command line or Power Shell, but let's act clearly and simply, without being afraid to make a mistake.
1. Download the free program WizTree
2. Scan the desired partition of the disk or select only the folder (F3) from the file menu. Scanning the entire disk takes 1-3 seconds. Folder scanning is even faster.
3. Click Sort by size and all folders will be sorted by size (descending / ascending)
Here's how it looks:

Screenshot
61afaa7d79af2629331012.png

4. Then, simply through Shift, select all folders less than 1 MB and delete them in one click.
The whole process will take you a minute.

R
res2001, 2021-12-07
@res2001

The main problem is to quickly find out the size of the directory. There are no standard cmd tools for this.
It remains only to do a recursive traversal of each directory and sum up the sizes of each file, as soon as the total size exceeds 1 MB, you can stop counting and skip the directory.
The size of a particular file can be obtained from the for /f loop variable using the %%~zi modifier. The same modifier applies to numbered procedure parameters.
See:

for /?
call /?
set /?
rmdir /?

K
kisaa, 2021-12-07
@kisaa

I would look towards PowerShell:
woshub.com/powershell-get-folder-sizes

H
hint000, 2021-12-07
@hint000

If this is not a task that needs to be performed regularly, but a one-time task, then it can be done manually in just a few seconds (not counting the time that Windows spends deleting and calculating the size of folders).
Run FAR manager , open the desired folder, enable sorting by size, select all files and folders with an asterisk or plus (maybe you need to enable folder selection in the settings), press F3. This will calculate the size of all selected folders. Since sorting by size has been enabled, it remains only to hold down the ins key to correct the selection so that folders smaller than 1 MB are selected. Now delete them via F8 or Del.
I guess that a similar trick can be done through Total Commander, but I have never been a fan of it and therefore I can’t say for sure about it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question