home bbs files messages ]

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

   alt.msdos.batch      Fun with MS-DOS batch files      42,547 messages   

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

   Message 42,067 of 42,547   
   Auric__ to Homer Wilson Smith   
   Re: Win98 DOS name a file with the date.   
   06 Oct 22 18:11:39   
   
   From: not.my.real@email.address   
      
   Homer Wilson Smith wrote:   
      
   > Running Win98 4.10.2222 DOS 5.x or 6.x batch scripts   
   >   
   > Need to write a file or directory with the date.   
   >   
   > echo %date% does not work as it does in future windows.   
   >   
   > Is there a batch script command that will do this for me?   
      
   If it needs to be DOS-compatible, QBasic is an option. (Robert's suggestion   
   of VBscript won't work under DOS.) Save this to a file called something like   
   "MDDATE.BAS":   
      
   '---begin---   
     'create directory using today's date as the name   
     ON ERROR GOTO ender   
     x$ = DATE$   
     'y$ is the created directory name in YYYYMMDD format   
     '    year            month          day   
     y$ = RIGHT$(x$, 4) + LEFT$(x$, 2) + MID$(x$, 4, 2)   
     MKDIR y$   
     ender:   
     SYSTEM   
   '---end---   
      
   ...and save this to something like "MFDATE.BAS":   
      
   '---begin---   
     'create file using today's date as the name   
     ON ERROR GOTO ender   
     RANDOMIZE TIMER   
     x$ = DATE$   
     'y$ is the created file name in YYYYMMDD format   
     'change ".txt" to whatever you want   
     '    year            month          day   
     y$ = RIGHT$(x$, 4) + LEFT$(x$, 2) + MID$(x$, 4, 2) + ".txt"   
     z$ = LTRIM$(STR$(INT(RND * 100000000)))   
     'this nonsense needed because qbasic lacks functionality   
     SHELL "dir /b " + y$ + ">" + z$ + ".tmp"   
     OPEN z$ + ".tmp" FOR INPUT AS 1   
     IF LOF(1) < 1 THEN   
       'file does not exist; create   
       OPEN y$ FOR BINARY AS 2   
     END IF   
      
     ender:   
     ON ERROR GOTO ender2   
     CLOSE   
     KILL z$ + ".tmp"   
     ender2:   
     SYSTEM   
   '---end---   
      
   Then call the appropriate script at the point in your batch that you need to   
   create your file:   
      
     QBASIC /RUN MFDATE.BAS   
      
   ...or directory:   
      
     QBASIC /RUN MDDATE.BAS   
      
   --   
   When life shuts a door, open it back up.   
   That's how doors work.   
   Then shut it again.   
      
   --- 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