# Solved: How to change all files to zero-byte?



## auaa (Feb 2, 2010)

Hi, is there any way I can change all files in a folder to zero-byte length? I need to have the same filenames, just want to change their size to zero. Maybe by creating a batch file.

Please help. Thanks.


----------



## Squashman (Apr 4, 2003)

If you are doing it in pure batch you would have to delete the existing file first and then create a new file with the same name that is zero byte.

Use a For Loop with the dir command to parse the directory to get the filenames and delete the old and create a new one with the same name.


----------



## Squashman (Apr 4, 2003)

This should work

```
@ECHO OFF
:: set your folder name here.
set _folder=E:\Zero byte files
pushd %_folder%
FOR /F "Tokens=*" %%I In ('Dir /a-d /b') Do (copy /Y nul "%%I")
popd
```


----------



## auaa (Feb 2, 2010)

Squashman said:


> This should work
> 
> ```
> @ECHO OFF
> ...


Thanks for helping Squashman, that codes really works !! 

Thank you.


----------

