سؤال

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