Computing Staff
  • 3

Insert Filename Into First Column In CSV File

  • 3

Hi There!

I have many output files (500+).

The file names reflect the username, for example: “firstname lastname.csv”

A snapshot of each file is as follows:

Application Name,Description,Version,Vendor,Copyright
” Crypto 1 Library”,””,,””,””

Each CSV contains upwards of 100 lines, but essentially follows the above formats.

So I’m trying to write a batch file that will take my list of files which I have in a text file (filelist.txt), insert the name of the file into each CSV as the first column.

I can them merge them myself and work with the information.

Advice apprecaited!

Thanks in advanced 🙂 WM

Share

1 Answer

  1. Code below:

    for /f “usebackq tokens=* delims=,” %%G in (filelist.txt) do (
    @echo off > #

    for /f “usebackq tokens=* delims= ” %%i in (%%G) do (
    >> # echo.”%%G”, “%%i”
    )
    move /y # %%G
    )

    • 0