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 68,038 of 68,980   
   John Stockton to All   
   Re: Set an environment variable YWD to c   
   13 Apr 23 03:50:57   
   
   From: dr.j.r.stockton@gmail.com   
      
   On Thursday, 13 April 2023 at 06:29:29 UTC+1, JJ wrote:   
   > On Wed, 12 Apr 2023 03:58:34 -0700 (PDT), Adam Lubszczyk wrote:   
   ... ...   
   > > FOR /F "tokens=*" %%a IN (file_name.txt) Do CALL :label1 "%%a"   
   ... ...   
   > > Adam   
      
   I saw that yesterday, and has been thinking about "FOR /F" and not needing a   
   "CALL"; but decided to leave that until today.   
      
   > Characters 20-29 is inclusive. Meaning that, 10 characters are extracted.   
   Yes.   
   So   
   > it should be:   
   > SET YWD=%YWD:~19,10%   
   that is better, but ...   
      
   > FYI, shorter version of the code:   
   >   
   > @ECHO OFF   
   > SETLOCAL   
   > SET YWD=   
   > FOR /F "usebackq tokens=*" %%a IN ("file name.txt") do set "YWD=%%a"   
   > SET "YWD=%YWD:~19,10%"   
   > ECHO %YWD%   
      
   The code is actually in the start-up file for a CMD.EXE window, so SETLOCAL   
   had to be removed.  H'mm - it should be  in the log-in setup file for a User,   
   or the one for All Users.  For me, that is not important.   
      
   As is, the "19" must be "17", because the input line starts with two spaces;   
   so perhaps "tokens=*" is not needed.   
      
   > Use of `backq` option is recommended to allow parsing file whose name   
   > contains space or special character.   
      
   The file name is "INC-YWWD.JS", and I have no expectation of changing it in   
   any way!   
   I use short names for manually-executed routines (e.g. "N" calls N.BAT which   
   calls an improvement on "dir | find "%date% | sort") and four-letter ones   
   .TXT for complex reasons. But otherwise   
   I use only upper-case letters, digits, minus signs, and the "8.3" pattern - -   
   - except sometimes.   
      
   The context of that file is currently machine-generated on CMD.EXE  start-up,   
   the only regular change being to the values of digits in it.  My YWD is   
   actually the ISO-8601 Week-Numbering Date.   
      
   So, question solved, but the actual code has been learned from, and may be   
   adjusted a little.   
      
   Thanks.   
      
   --- 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