Dir / b on one line with DELIMITER added. Programming batch files

I want the dir / b command line to be displayed on one line, separated by a delimiter, for example, Out

dir c:\test file1 file2 file3 file4 

I want him to be

 file1;file2;file3;file4 

How to do this with batch programming.

+4
source share
2 answers
 @echo off setlocal enabledelayedexpansion enableextensions set LIST= for %%x in (*) do set LIST=!LIST!;%%x echo %LIST:~1% 

This will not indicate the names of the files that contain ; . However, the following:

 @echo off setlocal enabledelayedexpansion enableextensions set LIST= for %%x in (*) do ( echo %%x|findstr ";">nul 2>&1 if errorlevel 1 (set LIST=!LIST!;%%x) else (set LIST=!LIST!;"%%x") ) echo %LIST:~1% 
+6
source

Maybe pass it through a python script, for example:

 import sys print ';'.join(sys.stdin.read().split()) 

In your batch file:

 dir /b | thatscriptjustabovehere.py 
0
source

Source: https://habr.com/ru/post/1337261/


All Articles