I need to write a script in batch to do the following:
- For each csv in the folder check the first character (first character of the first line)
- If it is "*" then add a first row from another txt file ("header.txt")
I have written the following code in batch:
@echo off
pushd %~dp0
for %%F in (*.csv) do (
for %%a in ("%%F") do set "var=%%a"&goto :stop
stop:
set var=!var:~0,1!
if %var% == "*" (
type "header.txt" >> "Temp.csv"
type "%%F" >> "Temp.csv"
del "%%F"
ren "Temp.csv" "%%F")
)
This code without "if condition" works:
@echo off
pushd %~dp0
for %%F in (*.csv) do (
type "header.txt" >> "Temp.csv"
type "%%F" >> "Temp.csv"
del "%%F"
ren "Temp.csv" "%%F")
)