Home > Software design >  Bat file to list files, using semicolon delimiter?
Bat file to list files, using semicolon delimiter?

Time:01-09

So far I have this:

@ECHO OFF

dir *.txt /c /b /on > content.txt

Which gives output:

file1.txt
file2.txt
file3.txt

But I need it like this, separated with semicolon on each line:

file1.txt;
file2.txt;
file3.txt;

I assume I probably need to write for loop and add string ";" somewhere, but I don't know where or how to do this. Or is there a way to just set a specific delimiter?

CodePudding user response:

Quick single line answer:

@(For /F Tokens^=*^ Delims^=^ EOL^= %%G In ('Dir "*.txt" /A:-D /B /O:N 2^>NUL') Do @Echo %%G;) 1>"content.log"

…and in :

(For /F Tokens^=*^ Delims^=^ EOL^= %G In ('Dir "*.txt" /A:-D /B /O:N 2^>NUL') Do @Echo %G;) 1>"content.log"

I have decided to output to a .log file, so that the listing doesn't include itself.

Please use the built-in help to learn how each command works.

CodePudding user response:

You can try :

sed -i '/.txt/s/$/;/' content.txt

  •  Tags:  
  • Related