1

I am trying to create a batch file(s) that makes a folder, that contains 9 folders, with each of those 9 folders containing a text file, each of which has similar, but unique text.

What I have been able to scrap together is a batch that creates 1 instance of the text

rem Saved in D:\Temp\WriteText.bat
@echo off
@echo -ATTEDIT> ATTEDITChangeName.txt
@echo y>> ATTEDITChangeName.txt
@echo 36x24bdr>> ATTEDITChangeName.txt
@echo SUBTITLE>> ATTEDITChangeName.txt
@echo B209 11.5 TON BRIDGE ELEC LAYOUT>> ATTEDITChangeName.txt
@echo 612.9014,43.8533>> ATTEDITChangeName.txt
@echo 618.5063,35.8628>> ATTEDITChangeName.txt
@echo 109.9409,-6.7209>> ATTEDITChangeName.txt
@echo.>> ATTEDITChangeName.txt
@echo v>> ATTEDITChangeName.txt
@echo c>> ATTEDITChangeName.txt
@echo B209>> ATTEDITChangeName.txt
@echo B211>> ATTEDITChangeName.txt
@echo Next>> ATTEDITChangeName.txt

As well as another batch that creates a single folder.

echo ========================
:: CREATE FILES START
    cd /d "Manuals\Desktop\410 SCRIPT\Test\"
    md XXX

:: CREATE FILES END
    echo Done!
    pause >nul

I need help with:

  1. Either making these work together, or meshing them into one batch file
  2. Making the folder batch file, create 9 uniquely named folders inside the folder it already creates.
  3. Making it so that each of those 9 folders has its own .txt file, WHICH will end up having slightly different contents in each respective folder

The Iterations of Text

The only text that needs to change, is the text that currently says 'B209 11.5 TON BRIDGE ELEC LAYOUT" This needs to be something different in every folder.

This is for work, and to put it plainly, I am stumped. Any help would be greatly appreciated.

Thank you

EDIT:

  • B209 11.5 TON BRIDGE ELEC LAYOUT

  • B209 11.5 TON PANEL LAYOUT

  • B209 11.5 TON BRIDGE ELEC CONTROL PWR

  • B209 11.5 TON ELEC UTIL PWR

  • B209 11.5 TON 460VAC DRIVE

  • B209 11.5 TON PLC MOD 1 & 2

  • B209 11.5 TON PLC MOD 3 & 4

  • B209 11.5 TON PLC MOD 5 & 6

  • B209 11.5 TON MOD 7 & 8

user2813209
  • 91
  • 1
  • 1
  • 7

1 Answers1

0

Sadly, you're not very forthcoming about the nature of your subdirectory names or where this variant text is appearing from.

REM

@ECHO OFF
SETLOCAL
SET "parent=u:\Manuals\Desktop\410 SCRIPT\Test"
FOR %%d IN (xxx yyy zzz) DO (
 MD "%parent%\%%d" 2>nul
 >"%parent%\%%d\ATTEDITChangeName.txt" (
  FOR %%t IN (-ATTEDIT y 36x24bdr SUBTITLE) DO ECHO(%%t
  FOR /f "tokens=1,*delims==" %%s IN (q31147990.txt) DO IF /i "%%s"=="%%d" ECHO(%%t
  FOR %%t IN (
    "612.9014,43.8533" "618.5063,35.8628" "109.9409,-6.7209" 
    "" "v" "c" "B209" "B211" "Next") DO ECHO(%%~t
 )
)
GOTO :EOF

This code should generate the directories assigned to %%d and reads a file which I've named q31147990.txt and has the foemat

xxx=B209 11.5 TON BRIDGE ELEC LAYOUT
yyy=D209 11.5 TON BRIDGE ELEC LAYOUT
zzz=R209 11.5 TON BRIDGE ELEC LAYOUT

That is, the directory name = variant text.

On rethinking, here's a better version:

REM

@ECHO OFF
SETLOCAL
SET "parent=u:\Manuals\Desktop\410 SCRIPT\Test"
FOR /f "tokens=1,*delims==" %%d IN (q31147990.txt) DO (
 MD "%parent%\%%d" 2>nul
 >"%parent%\%%d\ATTEDITChangeName.txt" (
  FOR %%t IN (-ATTEDIT y 36x24bdr SUBTITLE) DO ECHO(%%t
  ECHO(%%e
  FOR %%t IN (
    "612.9014,43.8533" "618.5063,35.8628" "109.9409,-6.7209" 
    "" "v" "c" "B209" "B211" "Next") DO ECHO(%%~t
 )
)
GOTO :EOF

This second script reads each line of q31147990.txt, assigning the part before the = to %%d and the part after to %%e. It then creates the directory and generates a file with all of the required content. Note that there are two different forms of the for loop. Since the first loop is not creating any line from a string wich contains separators (spaces and commas), quotes are not required and hence %~t is not required. In the second loop, some of the strings contain commas, so each string is "quoted" and the quotes removed by the ~ in %~t.

Note that "" an empty line, and hence echo( is used. Although traditionally the character following echo is a space, there is a set of characters which may succeed the o and produce virtually the same result. Of these, ( is particularly useful because echo %something% where something is undefined will report echo is on/off but echo(%something% where something is undefined will produce a new line

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Let me try to explain a little bit more. The Title text (ie B209 11.5 TON BRIDGE ELEC LAYOUT) is different for each of the 9 subfolders. I edited my original post to include these. The titles of the 9 subfolders are all the same. See the gyazo link for what those are exactly. – user2813209 Jul 01 '15 at 15:34
  • This is a screenshot of the file structure. Those are the subfolder titles, and the end results of the contents of one text file. The LT TW Log file is irrelevant by the way. http://gyazo.com/c3df0b64ab208d422eac4f1bb80ee97d – user2813209 Jul 01 '15 at 15:38
  • I think I understand how your code works, but it is not producing any results. I made the text file it requires. Is there any other step I am missing? – user2813209 Jul 01 '15 at 15:45