-2

I was inspired on works of our colleagues from portal

Have a batch create text files based on a list
Batch script to read input text file and make text file for each line of input text file

to develop creation from a text file for example
"comps.txt" ( comp1,comp2....
for each PC a batch script read from a list of PCs in a text file and create a text file for each line of text as local.
Later in code are created folders files named - the same names ( comp1,comp2.... at the end we have text files : comp1.txt ,comp2.txt ... and folders: comp1 , comp2.... till 400 computers.
Any idea how to add in code or write another separate batch code to move for each coresponding folder text file for text file

comp1.txt->comp1 folder  
comp2.txt->comp2.txt  
....  

We have more than 400 lines!! I am very begginers for any scrips working very hard every single day and this is my first question. My code in Windows Batch is below

@echo off
  setlocal
   for /f "tokens=*" %%a in (comps.txt) do (type nul>"%%a.txt")
  for /f "tokens=*" %%a in (comps.txt) do (
   echo This is line 1 of text>"%%a.txt"
   )
   for /f %%i in (comps.txt) do mkdir %%i 
  do (
  echo "%%i.txt"
      )
  endlocal

[enter image description here]

Community
  • 1
  • 1

1 Answers1

1

It doesn't make any sense to generate text files and then folders to move the files to. Create the folders first place and create the files into the folders. Using a (code block) only one for loop is needed.

@echo off
setlocal
for /f "tokens=*" %%a in (comps.txt) do (
  if not exist "%%a" mkdir "%%a"
  echo This is line 1 of text>"%%a\%%a.txt"
)
endlocal
  • Many thanks -working perfectly with your help and code very much . That not only about txt file- For me that has a sense especially when You change inside code extension from " .txt->.bat [echo This is line 1 of text>"%%a\%%a.txt" ->echo This is line 1 of text>"%%a\%%a.bat" ] and You have computer folder name with same batch script name for futher modifications that can be given any variable - I will see Tommorow -time running too fast -Regards – Andrzej Orlecki Mar 16 '17 at 15:31