문제

How can i write batch file that stores result in a file in just one line? I want these 3 commands to write in new file ex. txt.txt in first line.

dir /b *.xml > txt.txt
echo 2 2 >> txt.txt
dir >> txt.txt

I want result to be in txt.txt file like this:

*.xml 2 2 dir
도움이 되었습니까?

해결책

Here's the code you wanted. Instead of "dir /B" you can place any other command. Or you can use the for loop several times to append output of multiple commands in a sigle line in output file.

@echo off
setlocal enabledelayedexpansion

rem create or empty output file
echo.|set /p some=>file.txt

for /F "tokens=*" %%a in ('dir /B') do (
    echo.|set /p some="%%a ">>file.txt
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top