0

I've written a batch file that creates a parent folder and subfolders like I want. However, I have 550 parent folders to make, so changing the directoryNAME variable each time isn't very efficient.

Instead, I've created a text file in which I've listed test names, one per line. The text file is in the same folder as the batch file and contains:

Test1
Test2
Test3

I'd like to have the following code to loop, replacing the directoryNAME variable, "Test1" each time with the string of the next product down the list until there are no more entries.

For example, in a perfect world, this code would run creating the parent folder "Test1", and then it would run again creating the parent folder "Test2" and so forth. These product names are located on individual lines in a text file in the same folder as the batch file.

SET directoryNAME="Test1"
SET filesNOTES="Files\Notes"
SET rootPATH="G:\My Drive\Company\Projects\Project1\Project1-1\Project1-1-1\Workflow\Generic Content"
mkdir %directoryNAME%
mkdir %directoryNAME%\Content
mkdir %directoryNAME%\Files\"Final Deliverables"
mkdir %directoryNAME%\Files\"Illustrator Files"
mkdir %directoryNAME%\Files\Notes
echo > %directoryNAME%\%filesNOTES%\FontInfo.txt
echo %directoryNAME%> %directoryNAME%\%filesNOTES%\FontInfo.txt
type %rootPATH%\FontInfo.txt >> %directoryNAME%\%filesNOTES%\FontInfo.txt
echo > %directoryNAME%\%filesNOTES%\"Mockup Notes".txt
echo %directoryNAME%> %directoryNAME%\%filesNOTES%\"Mockup Notes".txt
mkdir %directoryNAME%\Files\Notes
mkdir %directoryNAME%\Files\"Working PDFs"
mkdir %directoryNAME%\"Product Photos"\Finals 
mkdir %directoryNAME%\"Product Photos"\PSDs

I have no idea how to do this, but everything I've learned about writing batch files I've learned from this site, so I thought I'd come here first and try to figure this out.

Per Stephan's suggestion below, I started the code with:

for /f "delims=" %%a in (ProductList.txt) do echo %%a
SET filesNOTES="Files\Notes"

I also changed all directoryNAME variables to %%a, however this outputs a parent folder with the title %a instead of a product name.

I'm sure I'm doing this wrong, but any help would be appreciated.

  • Start with `for /f "delims=" %%a in (file.txt) do echo %%a` (if you try directly on command line, replace every `%%a` with `%a`). Read the output of `for /?` for more information – Stephan Jan 06 '18 at 20:00
  • I tried this, but I'm unsure how this changes the variable "directoryNAME" to the new line in the product list text file? Sorry if it's obvious, I'm brand new to coding and writing batch files. – Austin Duncan Jan 06 '18 at 20:20
  • just use `%%a`, *that's* your "directoryNAME". (have you tried the code in my first comment?) – Stephan Jan 06 '18 at 20:23
  • @Stephan I tried that, although since I'm pretty new at this I'm pretty sure I entered it wrong. I updated the post with what I have at the beginning now. – Austin Duncan Jan 06 '18 at 20:27

1 Answers1

0

(this should be a comment, but needs formatting)

for /f "delims=" %%a in (ProductList.txt) do (
  echo %%a
  REM you have a code block here
  REM and can insert several lines.
  REM %%a is valid until the block is closed. Like:
  ECHO mkdir "%%a\Files\Final Deliverables"
)
REM %%a isn't valid here any more

Read about delayed expansion when you work with code blocks.

Stephan
  • 53,940
  • 10
  • 58
  • 91