How to change all files to zero-byte?

February 2, 2010 at 07:45:37
Specs: Windows XP, 4.0 GB

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.


See More: How to change all files to zero-byte?

Report •


#1
February 2, 2010 at 08:46:19

Why would you want to do that. why not just delete them because that is in effect what you are doing by making them zero length. A file with nothing in it.

The easiest way to make a zero length file is delete the original then recreate it by opening and closing it without doing anything.

Stuart


Report •

#2
February 2, 2010 at 12:26:04

:: zerolgt.bat Usage: zerolgt Folder_Name
@echo off
pushd %*
for %%j in (*) do type nul > "%%j"
popd
:: End_Of_Batch


Report •

#3
February 2, 2010 at 21:46:31

Thanks IVO, that is the codes that I looked for. It works !! Just that, the batch file need to be put on same folder as the files need to be 'zero-byte'. At the end, the batch file also will be empty (zero byte). But that ok. :)

Actually StaurtS, I have a program that always update/download new files into certain folders. Eventhough I deleted the old (not-needed files), but this program will always download the same files that I already deleted. That is why I need a way to make the files to zero-byte. This program will still see the files are availalable (although with zero byte), and it will not download the same files into this folder.

Thanks again IVO.


Report •

Related Solutions

#4
February 3, 2010 at 02:50:28

"Just that, the batch file need to be put on same folder as the files need to be 'zero-byte'."

No, it doesn't


=====================================
Helping others achieve escape felicity

M2


Report •

#5
February 3, 2010 at 03:04:43

The zerolgt command should be issued from another directory with the target folder as a parameter, e.g.

C:\My dir>zerolgt C:\Documents and Settings\user\My Folder

However if you want to store it in the same folder holding the target files, use the following version

:: zerolgt.bat Usage: zerolgt Folder_Name
@echo off
pushd %*
for %%j in (*) do if /I not "%%j"=="%~nx0" type nul > "%%j"
popd
:: End_Of_Batch

The above script doesn't clear itself.

Report •

#6
February 3, 2010 at 06:54:35

> Why would you want to do that. why not just delete them
> because that is in effect what you are doing by making them
> zero length.
>

Not really, content is not the only information of a file ...


Report •


Ask Question