1

How to retrieve zero byte files and copy into a folder using batch script. can someone help me out.


i want the script should check the subfolders and displays the output as complete folder path in the output text file.


Operating system is WindowsXP. i would like to get the Zero byte files path and copy the path into a text file.

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300

2 Answers2

3

Create a batch file with the following commands:

@echo off
pushd %1
if exist *.txt for %%i in (*.txt) do if %%~zi==0 ECHO "%%i" >> list.txt
popd

This should find all the *.txt files of zero length and write the results to list.txt. Run the batch file from the directory where the files are located.

The following command would go through all the subfolders and the resulting txt file will contain full paths. @afrazier thanks for the correction.

for /r %i in (*.*) do if %~zi==0 ECHO "%i" >> list.txt
Sharjeel Aziz
  • 376
  • 3
  • 7
  • 3
    There's no need for the `if exist` check, just run the `for` loop directly. It'll loop over every file in the `(set)` or do nothing if there's no files to operate on. Also of note, doing `for /r %i` instead of `for %i` will go through all subfolders and the resulting list.txt will contain full paths. – afrazier May 14 '10 at 14:01
  • Thank you! Helped me figure out how to delete empty files. – Alek Davis Oct 19 '11 at 17:21
0

If you're on a *nix system, you can use find:

find / -size 0 -type f

PiL
  • 1,599
  • 8
  • 6