windowsappendechocommand-promptshrink

Use echo to empty file content in Windows Command Prompt


I have a folder on a windows laptop running a program for measuring concrete vibrations that runs 24/7. The software creates 2 files every 10 minutes *.asx and *.pbx The *.pbx files becomes 28 MB each. I run backup from the laptop to an ftp server every night. I would need to empty the files of its data, tried with echo and that works. but its thousands of files and i cannot figure out how to do it on all *.pbx extensions. Cannot remove the files, because then program will then restart the number sequence after 10 min. I need to keep all files in the directory just need to shrink them. The data in the files are not important after backup is finished.

I have tried echo delete >*.pbx and most of the arguments.

Please help!


Solution

  • Use FOR /F - loop command: against the results of another command.

    From command prompt:

    for /f "delims=" %G in ('dir /B *.pbx') do @copy /Y NUL "%~G">NUL
    

    From a Windows batch script (.bat or .cmd)

    @for /f "delims=" %%G in ('dir /B *.pbx') do @copy /Y NUL "%%~G">NUL