home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,001 of 68,980   
   JJ to Tim Rude   
   Re: Expand a variable within a variable   
   14 Aug 17 14:21:05   
   
   From: jj4public@vfemail.net   
      
   On Sun, 13 Aug 2017 23:20:51 -0500, Tim Rude wrote:   
   >   
   > OK, some more digging and experimenting and I've come up with this:   
   >   
   > @echo off   
   >   
   > setlocal enableextensions   
   >   
   > for /f "usebackq tokens=1,2,*" %%B IN (`reg query   
   > "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User   
   > Shell Folders" /v Desktop`) do set DT=%%D   
   >   
   > for /f "usebackq tokens=*" %%I in (`echo %DT%`) do set DESKTOP=%%~sI   
   >   
   > set DT=   
   >   
   > echo %DESKTOP%   
   >   
   > pause   
   >   
   > endlocal   
   >   
   > This seems to work fine in testing so far. I've also made it return the   
   > SFN rather than LFN of the desktop path since the old DOS app only works   
   > with 8.3 SFN's.   
   >   
   > See any issues here?   
      
   Usable in most cases, but not perfect, IMO.   
      
   The second FOR command would fail if %DT% contains a backquote character. Or   
   if the second FOR command doesn't use the backquote setting, and %DT%   
   contains a single-quote character. Both backquote and single-quote are valid   
   characters for file/folder names, although renamed special folders   
   themselves are highly unlikely.   
      
   One way to solve it is to substitute all backquote/single-quote characters   
   in the %DT% variable before using it for the FOR command with less commonly   
   used character (preferrably an ANSI character code within the range of 0x80   
   to 0xFF). Then undo the character substitutions after the variable is   
   expanded.   
      
   --- 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