I have a requirement to identify a zero KB file in a folder and write the output to a text file. Below is the code I found by using batch script and I would like to customize the same as per my below requirement.
@echo off
set out=found.txt
(for /r c:\myfolderfilestosearch %%F in (*.txt) do (if %%~zF LSS 1 echo %%F)) > %out%
pause
I would actually want to create & write the result to file if and only if the above folder has any of the 0kb files only, but my above script creates a txt file for every instance even if there are no 0KB files.
I think we can implement it by using if else but as I said I am new and appreciate if someone guides on it with a script.
P.S. I am fine to have a script written in powershell as well.Thanks.
for %%a in (%out%) do if %%~za == 0 del %out%(I would use== 0orequ 0instead oflss 1)