Running all files in directory via batch file with appended text on each line

江枫思渺然 提交于 2019-12-23 05:17:59

问题


I'd like to create a batch file that

A) Reads all files in the current directory

B) Writes all files in the current directory to another batch file

C) Appends text to each line (I want to append "/Z /U" (for quiet and norestart respectively)

What I have so far:

BATCH FILE

@echo on

@setlocal enableextensions
@cd /d "%~dp0"

dir /b > installALLTHETHINGS.bat

echo /Z /U >> installALLTHETHINGS.bat

The output of the batch file is here:

OUTPUT

exe1.exe
bat1.bat
installme.msi
bat2.bat
bat3.bat
file list.bat
/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?


回答1:


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
)


来源:https://stackoverflow.com/questions/15073139/running-all-files-in-directory-via-batch-file-with-appended-text-on-each-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!