Combine two scripts to process directory

December 21, 2010 at 12:10:47
Specs: Windows XP
I have found some code ( in this forum) that works on an individual txt file to remove all the quotes and saves as a CSV, works a treat!
*********************************************
:: remove double quotes

@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (file.txt) do (
set str=%%a
set str=!str:"=!
>> Done.csv echo !str!
)
*******************************************************
What I would like to do is process a whole directory of txt files
so that
orignalFile.txt becomes originalFile.csv
having only some rudimentary Java and SQL experience I'm struggling a bit to figure out what is going on in this code,, its some sort of for loop i'm guessing
so any explanations of what is actually happening would be useful also.

and next... some more pinched code from the this forum that works brilliantly on my data
to concatenate all the csv files into one file with the the same headers
********************************************************************
setlocal enabledelayedexpansion
@echo off
del all.csv
set header = column1, coloumn2, column3,.........
::change the content of header, above

for %%a in (*.csv) do type %%a>>all.tmp
echo %header%>ALL.CSV

for /f tokens=1,* delims= %%b in (all.tmp) do (
set x=%%b
call :all2
)
del all.tmp
goto :eof

:all2
for /f tokens=1,* delims= %%c in (!x!) do set y=%%c
if !y!==!header! goto :eof
echo !y! >> ALL.CSV
goto :eof
*********************************************************

Again I can see three loops but whats going on? are they nested ??
Any way
Ideally i would like to combine both these scripts so I can process a directory of .txt files to become one CSV file without any quotes in it.

Help guidance suggestions or links to relevant posts appreciated

Many thanks


See More: Combine two scripts to process directory

Report •


#1
December 22, 2010 at 09:51:07
THIS is what I have so Far but it still not working properly
******************************************************************
setLocal EnableDelayedExpansion

for %%z in (*.txt) do type "%%z">>combined.txt

for /f "tokens=* delims= " %%a in (combined.txt) do (
set str=%%a
set str=!str:"=!
echo !str! >> combined.tmp
)


set header = colum1,colom2,........


echo %header%>Completed.CSV

for /f tokens=1,* delims= %%b in (Combined.tmp) do (
set x=%%b
call :all2
)
del Combined.tmp
goto :eof

:all2
for /f tokens=1,* delims= %%c in (!x!) do set y=%%c
if !y!==!header! goto :eof
echo !y! >> Completed.CSV
goto :eof
********************************************************************************

First I noticed that in the combined.txt file
There is a square charachter at the beginning of the first line of where each of the text files gets imported.

The combined.tmp file doesnt get deleted so its not making it through that far
but if I open the combined.tmp as a csv file its all there, the headers are duplicated. Also all the headers have this  concatenated onto the beginning of the first colum header name. similar thing to little square in the txt file

and the Completed.CSV file is empty except for the first line which says
Echo is Off,, or echo is on if its turned on



Report •
Related Solutions


Ask Question