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,007 of 68,980   
   Tim Rude to All   
   Re: Expand a variable within a variable   
   14 Aug 17 14:50:20   
   
   From: timrude.nospam@nospam.hotmail.com   
      
   On 8/14/2017 10:16 AM, Zaidy036 wrote:   
   > On 8/13/2017 10:58 PM, Tim Rude wrote:   
   >> I'm trying to obtain the current user's desktop path to pass as a   
   >> command-line parameter to an old DOS app that will be running under   
   >> Win7/8/10.   
   >>   
   >> I can get the path from the registry using:   
   >>   
   >> 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   
   >>   
   >> On a default install of Win7, that sets the %DT% environment variable   
   >> to '%USERPROFILE%\Desktop' since that's what's stored in the registry.   
   >>   
   >> However, I need the '%USERPROFILE%' part expanded to the actual path,   
   >> so that I end up with %DT% being (for example) 'C:\Users\Tim\Desktop'.   
   >>   
   >> How can I get my batch file to expand the %USERPROFILE% variable   
   >> that's within the %DT% environment variable?   
   >   
   > SET DT=%DT:Desktop=%   
      
   Huh? I'm not wanting to strip off the word 'Desktop', I'm wanting it to   
   expand '%USERPROFILE%\Desktop' into 'C:\Users\TRR\Desktop'.   
      
   I think I've managed that with   
      
   for /f "usebackq tokens=*" %%I in (`echo %DT%`) do set DESKTOP=%%~sI   
      
   but if there is a nifty way to do something similar using the SET   
   command, I'm all ears.   
      
   --- 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