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,989 of 68,980    |
|    JJ to icaro    |
|    Re: split a variable that contains a pat    |
|    01 Jan 23 14:50:05    |
   
   From: jj4public@outlook.com   
      
   On Sun, 01 Jan 2023 01:25:53 +0100, icaro wrote:   
   > Hi all,   
   > I have a batch file with a variable containing a random path, eg   
   > C:\some\thing\not\so\useful   
   > and I need to have an output splitted in this way (the first line must   
   > contail the drive and the first directory)   
   >   
   > C:\some   
   > C:\some\thing   
   > C:\some\thing\not   
   > C:\some\thing\not\so   
   > C:\some\thing\not\so\useful   
   >   
   > Could you please help me?   
   > Regards   
   > Icaro   
      
   This should do it.   
      
   @echo off   
   setlocal   
      
   set "p=C:\some\thing\not\so\useful\"   
      
   for %%A in ("%p%") do set "p=%%~dpnxA"   
   if "%p:~-1%" == "\" set "p=%p:~0,-1%"   
   set n=0   
   call :disppath "%p%"   
   for /l %%A in (%n% -1 1) do call echo %%p%%A%%   
   pause   
   goto :eof   
      
   :disppath   
   set "a=%~dp1"   
   if "%a:~-1%" == "\" set "a=%a:~0,-1%"   
   set/a n+=1   
   set "p%n%=%~1"   
   set "s=%a:\=%"   
   if "%s%" == "%a%" goto :eof   
   call :disppath "%a%"   
      
   --- 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