How to Get Files with Size Greater than 0 Bytes in CMD
• 1 min read
cmd command-prompt files forfiles windows
You can use the forfiles command in Command Prompt (CMD) to list files with a size greater than 0 bytes in a directory:
forfiles /P directory_path /M * /C "cmd /c if @fsize gtr 0 echo @path"
In this example, the forfiles command followed by a path lists all files in the specified directory with a size greater than 0 bytes.
The following example shows how to use this syntax in practice.
Example: How to Get Files with Size Greater Than 0 in CMD
Suppose that we want to list files with a size greater than 0 bytes in the following directory:
C:\Users\admin\Documents\cmd_script
We can type the following command to list the files:
forfiles /P C:\Users\admin\Documents\cmd_script /M * /C "cmd /c if @fsize gtr 0 echo @path"
```powershell
Output: 👇️
!CMD - Get files with size greater than 0 bytes
We can see that all files with a size greater than 0 bytes in **C:\Users\admin\Documents\cmd_script** are listed.
## Conclusion
In this article, we use the **forfiles** command followed by the directory path to list files with a size greater than 0 bytes in a directory on your system.
You can find more topics about Active Directory tools and PowerShell basics on the [ActiveDirectoryTools](https://activedirectorytools.net/) home page.