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