home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / 4os2300.zip / EXAMPLES.BTM < prev    next >
Text File  |  1997-07-30  |  13KB  |  328 lines

  1. :: examples.btm
  2. :: 24-jul-97
  3. ::
  4. :: Copyright 1997, JP Software Inc., All Rights Reserved.
  5. :: Published by JP Software Inc., P.O. Box 1470, E. Arlington, MA 02174,
  6. :: USA, or http://www.jpsoft.com/
  7. ::
  8. :: This sample batch file is distributed with 4DOS, 4OS2, 4NT, and Take
  9. :: Command.  To see how it works simply run EXAMPLES from your command
  10. :: processor's prompt.
  11. ::
  12. :: You are free to extract items from this batch file for your own use with
  13. :: our products.  However, this file can not be modified and then
  14. :: redistributed; it is distributed only by JP Software Inc.
  15. ::
  16. *@echo off
  17. *setlocal
  18. *unalias *
  19. *unset *
  20. on break goto done
  21. on error rem
  22. window max
  23. do forever
  24.   cls
  25.   echos Executing: %_batchname under
  26.   ver /r
  27.   text
  28.  
  29.   This batch file contains a few basic examples of how the
  30.   various variable functions can be used in your own code.
  31.  
  32.   Please press a number [0-8] corresponding to one of the categories
  33.   below to see some sample output, or any other key to exit.
  34.  
  35.       0. LIST this batch file
  36.       1. System status
  37.       2. Drives and devices
  38.       3. Files
  39.       4. File names
  40.       5. Strings and characters
  41.       6. Numbers and arithmetic
  42.       7. Dates and times
  43.       8. Utility
  44.  
  45.   endtext
  46.   inkey /c /p /w60 /x Which? %%s
  47.   cls
  48.   iff islabel _%s then
  49.     gosub _%s
  50.     echo ``
  51.     echo ``
  52.     iff "%s" ne "0" then
  53.       echos   Press "L" to LIST this section,
  54.       echos  any other key to return to the menu
  55.       inkey /c /p /x %%i
  56.       if "%i" eq "L" list /t":_%s" %_batchname
  57.     endiff
  58.   else
  59.     leave
  60.   endiff
  61. enddo
  62. :done
  63. window rest
  64. quit
  65. ::
  66. :_0
  67. list %_batchname
  68. return
  69. ::
  70. :_1
  71. echo    1.FUNCTIONS: System status
  72. echo ``
  73. setdos /x-5
  74. echo %%@DOSMEM[[b|k|K|m|M]c]    Free DOS memory:       %@dosmem[bc] bytes
  75. echo %%@EMS[[b|k|K|m|M]c]       Free EMS memory:       %@ems[bc] bytes
  76. echo %%@XMS[[b|k|K|m|M]c]       Free XMS memory:       %@xms[bc] bytes
  77. echo %%@EXTENDED[[b|k|K|m|M]c]  Free extended memory:  %@extended[bc] bytes
  78. setdos /x5
  79. echo ``
  80. set jp=foo
  81. set /m jp=bar
  82. if "%@master[jp]" ne "" echos %%@MASTER[varname]
  83. iff "%@master[jp]" eq "%jp" then
  84.    echo          String "%%JP" expands to "%@master[jp]" in a single master/local environment.
  85. else
  86.    echo          String "%%JP" expands to "%jp" locally (shell #%_shell), but to "%@master[jp]" in the master environment.
  87. endiff
  88. unset /m jp
  89. echo ``
  90. echo %%@READSCR[row,col,len]    The six characters starting with the ninth
  91. echo                           column of the top row of the screen are
  92. echo                           "%@readscr[0,8,6]"
  93. return
  94. ::
  95. :_2
  96. echo    2.FUNCTIONS: Drives and devices
  97. echo ``
  98. set i=%_disk
  99. echo  (using current drive "%i:")
  100. echo ``
  101. echo %%@DISKTOTAL[d:,M]     Total disk space: %@format[12,%@disktotal[%i,M]] MB
  102. echo %%@DISKUSED[d:,K]      Used disk space:  %@format[12,%@diskused[%i,K]] KB
  103. echo %%@DISKFREE[d:,b]      Free disk space:  %@format[12,%@diskfree[%i,b]] bytes
  104. echo %%@LABEL[d:]           Volume label:     %@format[13,"%@label[%i]"]
  105. echo %%@CDROM[d:]           Drive is %@if[%@cdrom[%i] eq 0,NOT ,]a CD-ROM
  106. echo %%@READY[d:]           Drive is %@if[%@ready[%i] eq 0,NOT ,]ready
  107. echo %%@REMOTE[d:]          Drive is %@if[%@remote[%i] eq 0,NOT ,]remote
  108. echo %%@REMOVABLE[d:]       Drive is %@if[%@removable[%i] eq 0,NOT ,]removable
  109. echo %%@FSTYPE[d:]          The file system is %@FSTYPE[%i]
  110. echo ``
  111. echo %%@DEVICE[name]
  112. for %i in (NUL: CON: COM1: COM5: CLIP:) (
  113.   echo                       Device %i %@if[%@device[%i] eq 0,NOT ,]found
  114. )
  115. echo %%@LPT[n]              Printer port LPT2 is %@if[%@lpt[2] eq 0,NOT ,]ready
  116. return
  117. :_3
  118. echo    3.FUNCTIONS: Files %@if[%_rows lt 26,(screen 1),]
  119. echo ``
  120. set i=%_batchname
  121. echo  (using this batch file as "filename")
  122. echo ``
  123. if x%@descript[%i] eq x describe "%i" "Batch language examples"
  124. echo %%@DESCRIPT[filename]             %@descript[%i]
  125. echo %%@TRUENAME[filename]             %@truename["%i"]
  126. echo %%@ALTNAME[filename]              %@altname["%i"]
  127. echos %%@ATTRIB[filename,[nrhsda]]      File is %@if[%@attrib["%i",r,p] eq 0,NOT ,]readonly
  128. echo  (%@attrib["%i"])
  129. echo %%@FILEAGE[filename]              %@fileage["%i"]
  130. echo %%@FILEDATE[filename]             %@filedate["%i"]
  131. echo %%@FILETIME[filename]             %@filetime["%i"]
  132. echo %%@LINES[filename]                This file contains %@lines["%i"] lines
  133. echo %%@LINE[filename,n]               Its sixth line is "%@line["%i",5]"
  134. echo                                  and its last line is "%@line["%i",%@lines["%i"]]"
  135. echo ``
  136. echos %%@FILEOPEN[filename,mode]
  137. set jp=%@fileopen[%i,read,b]
  138. echo         Open file for READ in BINARY mode as handle #%jp
  139. echos %%@FILESEEK[n,offset,start]       Move pointer 8 bytes from beginning
  140. echo  (result=%@fileseek[%jp,8,0])
  141. echos                                  Move another 10 bytes
  142. echo  (result=%@fileseek[%jp,10,1])
  143. echo %%@FILEREAD[n [,length]]          Read next 5 bytes: "%@fileread[%jp,5]"
  144. echo %%@FILECLOSE[n]                   Close handle #%jp: result=%@fileclose[%jp]
  145. echo ``
  146. if %_rows lt 26 (
  147.   pause Presss any key for more ...
  148.   cls
  149.   echo    3.FUNCTIONS: Files (screen 2)
  150.   echo ``
  151. )
  152. set i=*.txt
  153. set j=%@filesize[%i,b]
  154. if %j eq -1 set j=0
  155. echo %%@FILESIZE[%i,b]              "%i" files occupy %j bytes
  156. echo %%FILES[%i]                    with %@files[%i] matching file(s)
  157. echo                                  in this "%_cwd\" directory.
  158. echo ``
  159. set i=\*
  160. echo %%@FINDFIRST[filename[,-nrhsda]]  First directory in the root: "%@findfirst[%i,d]"
  161. echo %%@FINDNEXT[filename[,-nrhsda]]   Next directory in the root: "%@findnext[%i,d]"
  162. echo                                  Next directory in the root: "%@findnext[%i,d]"
  163. echo                                  etc.
  164. echo %%@FINDCLOSE[filename]            Close search handle for "%i" (result=%@findclose[%i])
  165. echo ``
  166. set i=%@unique[.]
  167. echo %%@UNIQUE[d:\path]                Create file with unique name: %@filename["%i"]
  168. *del %i
  169. return
  170. ::
  171. :_4
  172. echo    4.FUNCTIONS: File names
  173. echo ``
  174. set i=%_batchname
  175. echo  (using this batch file as "filename")
  176. echo ``
  177. echo %%@EXT[filename]       Extension only:      %@ext["%i"]
  178. echo %%@FULL[filename]      Name with path:      %@full["%i"]
  179. echo %%@FILENAME[filename]  Name and extension:  %@filename["%i"]
  180. echo %%@NAME[filename]      Name only:           %@name["%i"]
  181. echo %%@PATH[filename]      Path only:           %@path["%i"]
  182. echo %%@LFN[filename]       Long Name:           %@lfn[%i]
  183. echo %%@SFN[filename]       Short Name:          %@sfn[%i]
  184. echo ``
  185. echo %%@EXPAND[filename,[nrhsda]]     The *.TXT files in this directory are:
  186. echo    %@EXPAND[*.txt,-d]
  187. return
  188. ::
  189. :_5
  190. echo    5.FUNCTIONS: Strings and characters %@if[%_rows lt 26,(screen 1),]
  191. echo ``
  192. set i=%_dow
  193. echo %%@ASCII[c]                      Numeric ASCII value: "%i" is:
  194. echos                                 ASCII %@ascii[%@instr[0,1,%i]] +
  195. echos  ASCII %@ascii[%@instr[1,1,%i]] +
  196. echo  ASCII %@ascii[%@instr[2,1,%i]]
  197. echos %%@SUBSTR[string,start,length]   The middle character of "%i" is
  198. echo  "%@substr[%i,1,1]"
  199. echos %%@REPEAT[c,n]                   Repeat a character:
  200. echo       %@repeat[-,3] %@repeat[ ,5]-
  201. set i=   %i %_day`   `
  202. echo %%@TRIM[string]                  Remove blanks from "%i": "%@trim[%i]"
  203. set i=Windows
  204. echo %%@INSERT[n,string1,string2]     "%i" becomes "%@insert[4,s of sorr,%i]"
  205. set i=%@random[65,90]
  206. echo %%@CHAR[n]                       ASCII %i is character "%@char[%i]"
  207. echo %%@FORMAT[[-][x][.y],string]     `|`                  `|`
  208. echo               adjust right:     %@format[20,%_date]
  209. echo                                 %@format[20,%@eval[355/113]]
  210. echo                                 %@format[20.5,%@eval[355/113]]
  211. echo                adjust left:     %@format[-20,%_date]
  212. echo                                 %@format[-20,%@eval[355/113]]
  213. echo                                 %@format[-20.5,%@eval[355/113]]
  214. set i=*o[sw]*
  215. echos %%@WILD[str1,str2]               Wildcard "%i" DOES
  216. echo  %@if[%@WILD[%_cwd,%i] eq 0,NOT ,]appear in
  217. echo                                 "%_cwd".
  218. echo ``
  219. if %_rows lt 26 (
  220.   pause Presss any key for more ...
  221.   cls
  222.   echo    5.FUNCTIONS: Strings and characters (screen 2)
  223.   echo ``
  224. )
  225. set i=The bug which you would fright me with, I seek.
  226. echo  (using string "%i",
  227. echo   from William Shakespeare, The Winter's Tale, III,2)
  228. echo ``
  229. echo %%@LEN[string]                 The test string contains %@len[%i] characters.
  230. echo %%@LOWER[string]               "%@lower[%i]"
  231. echo %%@UPPER[string]               "%@upper[%i]"
  232. echo %%@WORDS[["sep",]string]       Number of words: %@words[%i]
  233. echo %%@WORD[["sep",]n,string]      Third word: "%@word[2,%i]"
  234. echos %%@INDEX[string1,string2]      The first "u" is character #
  235. echo %@index["%i",u]
  236. echos %%@INSTR[start,length,string]  The "f" is followed by:
  237. echo  "%@INSTR[%@index["%i",f],15,%i]..."
  238. echo %%@LEFT[n,string]              The leftmost 7 characters are "%@left[7,%i]"
  239. echo %%@RIGHT[n,string]             The rightmost 7 characters are "%@right[7,%i]"
  240. echo %%@REPLACE[str1,str2,str3]     "%@replace[ which you would,s you,%i]"
  241. echo %%@STRIP[chars,string]         No vowels: "%@strip[aeiuo,%i]"
  242. return
  243. ::
  244. :_6
  245. echo    6.FUNCTIONS: Numbers and arithmetic
  246. echo ``
  247. set i=%@eval[1234567890 / 100000]
  248. echo  (using an arbitrary number of %i)
  249. echo %%@COMMA[n]          Inserts thousands separators in a number: %@comma[%i]
  250. echo %%@DEC[%%var]         Decremented value of a variable: %@dec[%i]
  251. echo %%@INC[%%var]         Incremented value of a variable: %@inc[%i]
  252. echo ``
  253. echo %%@EVAL[expression]  Arithmetic calculations: 355 / 113 = %@eval[355 / 113=.5] (rounded)
  254. set n=%i
  255. echos %%@INT[n]            Integer part of a number - enter a number:
  256. input /c /x /e /l10 /w30 `` %%n
  257. screen %_row, %@eval[%_column - %@len[%n] - 27]
  258. iff %@numeric[%n] eq 0 then
  259.   beep
  260.   set n=%i
  261. endiff
  262. echo number %n is %@int[%n] `              `
  263. set i=%_4ver
  264. echos %%@NUMERIC[string]   Test if a string is numeric - enter string:
  265. input /c /x /e /l10 /w30 `` %%i
  266. screen %_row, %@eval[%_column - %@len[%i] - 36]
  267. echo string "%i" is numeric: %@numeric[%i] (0=No, 1=Yes)
  268. echos %%@RANDOM[min,max]   Generate a random integer:
  269. do 8 times
  270.   echos  %@random[0,7],
  271. enddo
  272. echo  etc.
  273. echo %%@CONVERT[in,out,value]       Base conversion:
  274. echo                                  decimal (10): %n
  275. echo                                  hexadecimal (16): %@convert[10,16,%n]
  276. echo                                  octal (8): %@convert[10,8,%n]
  277. echo                                  binary (2): %@convert[10,2,%n]
  278. return
  279. ::
  280. :_7
  281. echo    7.FUNCTIONS: Dates and times
  282. echo ``
  283. echo  (using the current system date of %_date and time of %_time)
  284. echo %%@DATE[mm-dd-yy]          Convert date to number of days: %@date[%_date]
  285. echo %%@MAKEAGE[date[,time]]    Convert date/time to file date/time: %@makeage[%_date[,%_time]]
  286. echo %%@TIME[hh:mm:ss]          Convert time to number of seconds: %@time[%_time]
  287. echo %%@DAY[mm-dd-yy]           Day of the month: %@day[%_date]
  288. echo %%@DOW[mm-dd-yy]           Day of the week: %@dow[%_date]
  289. echo %%@DOWI[mm-dd-yy]          Numeric day of the week: %@dowi[%_date]
  290. echo %%@DOY[mm-dd-yy]           Numeric day of the year: %@doy[%_date]
  291. echo %%@MONTH[mm-dd-yy]         Month of the year: %@month[%_date]
  292. echo %%@YEAR[mm-dd-yy]          Year number (2 digits): %@year[%_date]
  293. echo ``
  294. echo  (using an arbitrary number of 1234 days)
  295. echo %%@MAKEDATE[n]           Convert number of days to date: %@makedate[1234]
  296. echo ``
  297. echo  (using an arbitrary number of 1234 seconds)
  298. echo %%@MAKETIME[n]           Convert number of seconds to time: %@maketime[1234]
  299. echo ``
  300. echo  (combining date/time functions)
  301. echo In thirty minutes, the time will be %@maketime[%@eval[%@time[%_time]+1800]]
  302. echo In one week, the date will be %@makedate[%@eval[%@date[%_date]+7]]
  303. return
  304. ::
  305. :_8
  306. echo    8.FUNCTIONS: Utility
  307. timer on /3 > nul
  308. echo ``
  309. echo  (using a temporary alias for FORMAT)
  310. alias format=`beep%+echo Too dangerous! `
  311. echo %%@ALIAS[name]    Value of an alias: FORMAT is "%@alias[format]"
  312. unalias format
  313. echo ``
  314. echos %%@IF[condition,true,false]   Evaluates a test condition:
  315. echo  Good %@if[%_hour lt 12,morning,afternoon]!
  316. echo ``
  317. echo  (using this file as input - select a line from the box below)
  318. set i=%_batchname
  319. echos %%@SELECT[file,t,l,b,r,title]  Menu selection:
  320. echo  You selected "%@word[0,%@select[%i,12,2,17,25, This is a test ]]..."
  321. echo ``
  322. echo  (a TIMER was started when you displayed this page)
  323. echo %%@TIMER[n]                    Elapsed time of specified timer: %@timer[3]
  324. echo %%@CLIP[n]                     The first line of your Windows clipboard is:
  325. echo "%@clip[0]"
  326. return
  327. :: examples.btm
  328.