0

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 Answers1

0

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
)
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Thanks for the response dbenham! When I run this it doesn't appear to do anything unfortunately - i've tried with and without a pre-existing "installAllTheThings.bat" - I'll attempt to troubleshoot some more, but the /z /u doesn't appear after each line of code :( That said, this is new to me, and I'll update this if I can get it working. Oh, and the reason I want to do this is to install patches in batches as they come out - I don't have the ability to auto-install them. – Enterprise User Feb 28 '13 at 00:54
  • @user2029748 - Ughh, I don't know where my mind was when I wrote this answer. I just fixed 3 bugs. Try again with the modified code - it should work now. – dbenham Feb 28 '13 at 01:43
  • I realize it isn't required, but is there a way you can explain to me why if i name this file runme.bat and execute it, it doesn't pick up the filename runme.bat in the installAllTheThings.bat file? It's a good thing, I'm just not seeing in the code where this happens. Thanks! – Enterprise User Feb 28 '13 at 15:36
  • @user2029748 - The 1st IF prevents the installAllTheThings.bat from being included. The 2nd IF prevents the "runme.bat" from being included. – dbenham Feb 28 '13 at 15:45