Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 40,584 of 42,547    |
|    Todd Vargo to nathanwilson41@gmail.com    |
|    Re: Dynamic Setting of variable based on    |
|    21 Nov 12 00:56:45    |
   
   From: tlvargo@sbcglobal.netz   
      
   On 11/19/2012 5:01 AM, nathanwilson41@gmail.com wrote:   
   > All thanks for help so far but have hot a snag.   
   >   
   > The code above is working BUT   
      
   It would help if you post the exact batch along with the output in the   
   same posting as you are leaving us to guess which code in which post   
   above that you are referring to.   
      
      
   >   
   > The second entry the file name is not being used by the called process.   
   >   
   > It is using the value nx1 and not the value for the variable eg folderName   
   >   
   > As you can see from below it seems to be losing the variable.   
   >   
   > C:\Test>rem Get Files from Remote Location   
   >   
   >   
   >   
   > C:\Test>Set QM=D2MSBK61   
   >   
   >   
   >   
   > C:\Test>for / %A in (C:\Test\*) do (   
      
   Line above appears to be a typo. Should be "for /d..."   
      
      
   > for %B in ("%A\*") do call :process "%A" "%B"   
   >   
   > Set folderName=%~nxA   
   >   
   > Set fileName=%~nxB   
   >   
   > echo: UTILITY   
   >   
   > echo: %~nxB   
      
   You need to use delayedexpansion to use the variables set within the FOR   
   command. However, the purpose of the :process section to eliminate the   
   need for delayed expansion but the variables should be SET within the   
   :process section.   
      
   >   
   > )   
   >   
   >   
   >   
   > C:\Test>(   
   >   
   > for %B in ("C:\Test\A\*") do call :process "C:\Test\A" "%B"   
   >   
   > Set folderName=A   
   >   
   > Set fileName=%~nxB   
   >   
   > echo: UTILITY   
   >   
   > echo: %~nxB   
   >   
   > )   
   >   
   >   
   >   
   > C:\Test>call :process "C:\Test\A" "C:\Test\A\W.bar"   
   >   
   >   
   >   
   > C:\Test>Set folderName=nx1   
   >   
   >   
   >   
   > C:\Test>Set fileName=nx2   
   >   
   >   
   >   
   > C:\Test>echo Processing nx2 in nx1   
   >   
   > Processing nx2 in nx1   
   >   
   >   
   >   
   > C:\Test>echo Full Paths are "C:\Test\A\W.bar" and "C:\Test\A"   
   >   
   > Full Paths are "C:\Test\A\W.bar" and "C:\Test\A"   
   >   
   >   
   >   
   > C:\Test>call PROCESS.cmd D2MSBK61 nx1 nx2   
      
   It is unwise to name a batch file (process.cmd) with the same name as a   
   label (:process) within the calling batch. Again, since you did not   
   include the exact code used to produce this output, all I can do is   
   guess that is the case.   
      
      
   --   
   Todd Vargo   
   (Post questions to group only. Remove "z" to email personal messages)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca