1

Essentially:

I have several (400) text files each with a numerical file name (ie 12345.txt).

Each text file contains some text(Long description style, plain text paragraphs, etc). I am trying to figure out if I could import all of these text files into a spreadsheet for export to CSV.

The sheet would have two columns: the filename without the extension (the 12345), and the second column would be the contents of the file (single cell per file).

Thanks.

Remog
  • 163
  • 1
  • 8
  • You can merge text files into one by a batch command `copy *.txt target.txt`, then you can import into excel – Saju Mar 13 '13 at 12:19

1 Answers1

0

assuming all these files are in the same folder and no other .txt files are in that folder you could do the following

create 2 batch files

the for command can only result in 1 single other command to be executed, calling a second batch file is a single command which can contain all other commands required

test.bat

for %%f in (*.txt) do CALL test2.bat "%%f" "results.csv"

test2.bat

set str=%1
set resultfile=%2
set str=%str:~1,-5%
echo |set /p=%str%;>> %resultfile%
type %1 >> %resultfile%
echo ; >> %resultfile%

Run the batch file

Run the first batch file and all will be put in a csv called results.csv

K_B
  • 3,668
  • 1
  • 19
  • 29
  • You don't actually need 2 bat files just put :label before the text of bat2 but in same file as bat1 and call :label then put exit/b at the end. Does the same thing. Also you can but ( after do and wirte the lines inside for itself just close the parenthesis after the last echo. – joojaa Mar 15 '13 at 17:54