Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com May 14 '10 at 13:01

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

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
share|improve this answer
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
    
@afrazier thanks I have updated the answer. –  Shaji May 14 '10 at 14:23
    
Thank you! Helped me figure out how to delete empty files. –  Alek Davis Oct 19 '11 at 17:21
add comment

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

find / -size 0 -type f

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.