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,477 of 68,980   
   mokomoji to All   
   Re: remove duplicates   
   21 Jan 20 08:26:32   
   
   From: mokomoji@naver.com   
      
   2013년 4월 21일 일요일 오전 2시 1분 52초 UTC+9, Gabor Grothendieck   
   님의 말:   
   > I have a string that I wish to prepend to my path, say:   
   >    
   >   set x=C:\A;C:\A;C:\B;C:\A;C:\B;C:\B;C:\A   
   >    
   > Typically x has about 6 components but only 2 unique ones.  I do not know   
   ahead of time what the components are.  I would like to remove all but the   
   first occurrence of any component. We can assume that duplicate components   
   appear in the exact same    
   form as the non-duplicates, (e.g. we would never have both C:\X\Y and   
   C:/X/Y).  In the above example variable x's value is the input and the result   
   would be:   
   >    
   >   C:\A;C:\B   
   >    
   > Some desirable criteria include:   
   > - not to use any software that does not come with Windows   
   > - run quickly as its done on the fly each time I run an associated program   
   so it could affect the start up time if it were too slow   
   > - I would prefer not to write any files in doing this   
   >    
   > I guess I could just ignore this issue and just let there be duplicates on   
   the path (and in fact that is what I am currently doing) but if there is a   
   nice solution to this it would make the resulting PATH a bit cleaner.   
      
   path    
      
   @echo off   
   setlocal   
   set "x=%path%"   
   :main   
   for /f "delims=;" %%f in ("%x%") do (set "v=%%~f")   
   echo %x%|find /i /c "%v%" 2>nul>nul&&call set x=%%x:%v%;=%%&&call set   
   "z_f=%%z_f%%%%v%%;"   
   if "%v%" equ "%x%" goto :pr   
   goto :main   
   :pr   
   echo "%z_f%"   
   :end   
   pause   
   endlocal   
      
   --- 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