首页 > 解决方案 > write a batch output in a certain position on a text file, on a single line

问题描述

i would like to have the output from a batch routine (for example a dir comand) on a .txt file, then read it and take one line a the time and insert it inside a string on a .vbs file. The vbs file must send some comands to another batch so it requires that the text inside the string fits on a single line. I can't manage to insert the text, neither to fit it in one line.

the code goes something like this:

dir /s /b >> text.txt

for /f "tokens=*" %%i in(text.txt) do (echo %%i > comands.vbs)

@echo OBJECT.SendKeys ^" +()+.{ENTER} ^" > comands.vbs 

pause

I need the output of dir /s /b to be read and insert it where the +()+ is.

标签: batch-file

解决方案


You can use the FOR variable and insert that into the echo command. I think this is what you want to do but maybe I am over simplifying it.

@echo off

(for /F "delims=" %%G in ('dir /b /s') do (
    echo OBJECT.SendKeys "%%G {ENTER}"
)
)>commands.vbs

pause

推荐阅读