I am trying to figure out a way to have a batch script overwrite every instance of a non-zero byte file inside of a specific directory and its sub-folders. I'm guessing since I'm looking for a non-zero file I could probably loop it with a escape if it doesn't find any non-zero sized file?
Example, overwrite every instance of example.txt where it is a non-zero filesize:
D:\
\---SubFolder1
| example.txt <10 bytes>
|
\---Subfolder2
| example.txt <0 bytes>
|
\---Subsubfolder1
example.txt <20 bytes>
In the example, D:\Subfolder1\example.txt, and D:\Subfolder2\Subsubfolder1\example.txt would be overwritten, but D:\Subfolder2\example.txt wouldn't be changed.
Thank you to @NiKiZe for all your help!
Working Code:
@ECHO OFF
SET DPATH=%~dp0
FOR /R "%DPATH%" %%F IN (*** SEE BELOW) DO IF %%~zF
GTRNEQ 0 CALL :NonEmptyFile "%%~F"
GOTO :EOF:NonEmptyFile
ECHO Got non empty file: %1
CALL :EOF
*** Replace with filename that you are wanting to replace, be sure to use a single character wildcard somewhere (I used it in the extension - for example, if I am searching for example.txt, I replaced the * with example.t?t)