通过带有附加文本的批处理文件在每行上运行目录中的所有文件 [英] Running all files in directory via batch file with appended text on each line
问题描述
我想创建一个批处理文件
I'd like to create a batch file that
A)读取当前目录中的所有文件
A) Reads all files in the current directory
B)将当前目录中的所有文件写入另一个批处理文件
B) Writes all files in the current directory to another batch file
C)将文本附加到每行(我想添加/ Z / U安静和norestart分别)
C) Appends text to each line (I want to append "/Z /U" (for quiet and norestart respectively)
我到目前为止:
@echo on
@setlocal enableextensions
@cd /d "%~dp0"
dir /b > installALLTHETHINGS.bat
echo /Z /U >> installALLTHETHINGS.bat
批处理文件的输出位置如下:
The output of the batch file is here:
exe1.exe
bat1.bat
installme.msi
bat2.bat
bat3.bat
file list.bat
/Z /U
我确定我可以找出如何获得/ Z / U在最后一行,而不创建一个新行,但有一种方法,在每个文件后写/ Z / U在目录中?
I'm sure I can figure out how to get the "/Z /U" on that last line without creating a new line, but is there a way to write "/Z /U" after every file in the directory?
推荐答案
我不知道为什么要这样做, FOR循环。
I can't figure out why you want to do this, but it is simple to accomplish using a FOR loop.
@echo off
cd /d "%~dp0"
>installAllTheThings.bat (
for %%F in (*) do if "%%F" neq "installAllTheThings.bat" if "%%F" neq "%~nx0" echo "%%F" /Z /U
)
这篇关于通过带有附加文本的批处理文件在每行上运行目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!