title: How to read multiple text files using window batch scripting?
body: <p>Currently I am trying to read the variable value from different text files available in my directly folder and use those variable to execute commands like uploading the content to FTP server. </p>
  
  <p>I have different FTP servers on which I need to upload the same set of files. So what I want is to read the hostname, userID and password of different FTP servers which are saved in different text files and use those values to execute same set of commands for all. </p>
  
  <p>Here is my FileUpload.bat looks like :-</p>
  
  <pre><code>@echo off
  setlocal EnableDelayedExpansion
  for %%x in (C:\Users\xxxx\Desktop\Anivirus_Upload\text_*.txt)
      do ( 
      for /f "usebackq delims=" %%A in ("%%~Fx") 
          do (
              if "%%A"="user" set user=%%B
                  if "%%A"="password" set password=%%B
                  if "%%A"="localPath" set localPath=%%B
                  if "%%A"="serverpath" set serverpath=%%B
                  if "%%A"="Hostname" set Hostname=%%B    
                  echo  user %user%&gt; ftpcmd.dat
                  echo %password%&gt;&gt; ftpcmd.dat
                  echo lcd %localPath%&gt;&gt;ftpcmd.dat
                  echo cd %serverpath%/&gt;&gt;ftpcmd.dat
                  echo put %1&gt;&gt; ftpcmd.dat
                  echo quit&gt;&gt; ftpcmd.dat
                  ftp -n -s:ftpcmd.dat %Hostname%
                  del ftpcmd.dat
              ) 
      )
  </code></pre>
  
  <p>In the folder I have different text files namely </p>
  
  <pre><code>text_1 
  text_2
  </code></pre>
  
  <p>etc and each text file have values like :-</p>
  
  <pre><code>user=XXXX
  Hostname=10.164.XXXXX
  password=XXXXX
  localPath=C:\Users\XXXX\Desktop\Service_Pack_74
  serverpath=Temp/XXXX/Service_Pack_74/
  </code></pre>
  
  <p>I don't know where I am messing with the code while reading multiple text files. </p>
  
  <p>I checked my batch file with single text file and I am able to upload the content correctly so seems the issue is with the external for loop to read multiple files from the directory. </p>