0

I want all filesnames of the files in a folder and subfolders in a csv-file. For that I wrote a batchscript which works just fine:

set "Folder=N:\myFolder\mySubFolder\mySubSubFolder"
dir /b "%Folder%">"Z:\worx\filenames.csv"

The content of filenames.csv is like:

N:\myFolder\file1.txt
N:\myFolder\mySubFolder\file2.txt
N:\myFolder\mySubFolder\mySubSubFolder\file3.txt

Now I want to concatenate each line in the csv-file. The result has to look like that:

The File:N:\myFolder\file1.txt#exists
The File:N:\myFolder\mySubFolder\file2.txt#exists
The File:N:\myFolder\mySubFolder\mySubSubFolder\file3.txt#exists

Does anybody know a simple way to do that?

I thought about another batchfile which just extends each line of the csv-file, but I am looking for an less complicate way.

2 Answers2

0

Try this:

@echo off
set "Folder=N:\myFolder\mySubFolder\mySubSubFolder"
(for /f "delims=" %%a in ('dir /b /s /a-d "%Folder%" ') do echo The File:%%a#exists)>"Z:\worx\filenames.csv"
foxidrive
  • 40,353
  • 10
  • 53
  • 68
0
set "Folder=N:\myFolder\mySubFolder\mySubSubFolder"
(
for /f "delims=" %%x in ('dir /b "%Folder%"') do echo(The File:%%x#exists
)>"Z:\worx\filenames.csv"

Should work. The filenames are applied to %%x and output with the fixed text fore and aft. The "delims=" makes each dir /b line one string not a series of tokens. The parentheses surrounding the (for...) makes the redirector output any echoed text into the destination file. The > redirector creates the destination file anew. >> would append to any existing file.

You may wish to consider adding /a-d to your dir switches to suppress directorynames.

Magoo
  • 77,302
  • 8
  • 62
  • 84