Page 1 of 1

Batch delete first 67 character all text file in folder

Posted: 09 Jun 2020 03:27
by senonolo
Hi :)

I'm trying to remove the first 67 characters and here's what I've got so far:

Code: Select all

@echo off & setlocal enabledelayedexpansion
set "txt=*.txt"

set N=
for /f "tokens=* delims= " %%a in ('type "!txt!"') do (
set /a N+=1
if !N! lss 3 set S=!S!%%a
)
> Result.txt echo.!S:~67!

for /f "tokens=* skip=2 delims= " %%a in ('type "!txt!"') do (
echo.%%a
) >> Result.txt

goto :eof
It's work as expected only for one file.
I need it to loop the code for all files in a folder.

Can someone help me out?
Thanks! :D

Re: Batch delete first 67 character all text file in folder

Posted: 09 Jun 2020 09:44
by ShadowThief
> overwrites the file
>> appends to the end of the file

Re: Batch delete first 67 character all text file in folder

Posted: 15 Jun 2020 02:37
by penpen
You might want to use only one file per loop and add an outer loop (to not mix up files).
This might help you (but is untested):

Code: Select all

@echo off & setlocal enabledelayedexpansion
set "txt=*.txt"

:: the following line will delete the content of "Result.txt", if you don't want that delete it
>"Result.txt" rem:
for %%A in ("%txt%") do(
	set N=
	for /f "tokens=* delims= " %%a in ('type "%%~A"') do (
		set /a N+=1
		if !N! lss 3 set S=!S!%%a
	)
	>>"Result.txt" echo.!S:~67!

	for /f "tokens=* skip=2 delims= " %%a in ('type "%%~A"') do (
		echo.%%a
	) >>"Result.txt"
)

goto :eof
penpen