I created a script that converts a txt file into a csv and places commas in between the columns, but now I am trying to have place forward slashes in the third column between the number strings of this column. This column should be formatted as a date. My other issue is in this same column, sometimes it contains strings of dashes than I want removed. I cannot figure out how to do this, I have written the script as how I think it should work.
@ECHO off
SETLOCAL EnableDelayedExpansion
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set dow=%%i
set month=%%j
set day=%%k
set year2=%DATE:~-2%
set yearf=%%l
if "%%j"=="01" set mname=January
if "%%j"=="02" set mname=February
if "%%j"=="03" set mname=March
if "%%j"=="04" set mname=April
if "%%j"=="05" set mname=May
if "%%j"=="06" set mname=June
if "%%j"=="07" set mname=July
if "%%j"=="08" set mname=August
if "%%j"=="09" set mname=September
if "%%j"=="10" set mname=October
if "%%j"=="11" set mname=November
if "%%j"=="12" set mname=December
)
::Creates the folder structure based of the system date.
SET datestr=%month%%day%%year2%
SET "topdir=\\10.1.3.3\Information\Reports\Reports %yearf%\%month% %mname%\%day%"
::Outputs full File, this is the file that is used internally
SET "sourcedir=%topdir%"
SET "filename1=%sourcedir%\file%datestr%.txt"
FOR /f "usebackq tokens=1-3*" %%a IN ("%filename1%") DO (
SET bdd=!%%c:~2!
SET bmm=!%%c:~2,2!
SET byy=!%%c:~-4!
type %%c | findstr /v -
ECHO(%%a,%%b,%bdd%/%bmm%/%byy% >> "%topdir%\file%datestr%.csv"
)
PAUSE
This is the part I addedd,
SET bdd=!%%c:~2!
SET bmm=!%%c:~2,2!
SET byy=!%%c:~-4!
type %%c | findstr /v - ::trying to remove dashes from third column %%c
ECHO(%%a,%%b,%bdd%/%bmm%/%byy%
ECHO(%%a,%%b,%%c ::this is what works
Example txt file
245454 5454564 01032016
216545 5454543 2042016
211145 8878787 --------
How I want it formatted
245454,5454564,01/03/2016
216545,5454543,2/04/2016
211145,8878787,
Without this code, the script works just fine, but I'm not even close to knowing how this should be done. Thank you.