home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / makeimg.zip / MAKEIMG.CMD < prev    next >
OS/2 REXX Batch file  |  1996-02-07  |  4KB  |  118 lines

  1. /* REXX */
  2. parse arg parms
  3. parse var parms parms '/'option rest
  4. debug = FALSE
  5. start_disk = 1
  6. image_dir = ''
  7. rest = translate(rest)
  8. option = translate(option)
  9. do while (option > "")
  10.   select
  11.     when (left(option,1) = 'S') then
  12.        do
  13.          start_disk = substr(option,2)
  14.          if datatype(start_disk) <> 'NUM' then call Usage("Invalid /S option")
  15.        end
  16.     when (left(option,1) = 'I') then
  17.        do
  18.          image_dir = substr(option,2)
  19.          if right(image_dir,1) = '\' then image_dir = left(image_dir,length(image_dir) - 1)
  20.        end
  21.     when (left(option,1) = 'T') then
  22.        do
  23.          debug = TRUE
  24.        end
  25.     otherwise;
  26.        call Usage "Invalid option:" option
  27.   end
  28.   parse var rest '/'option rest
  29. end
  30. if image_dir > '' then
  31. do
  32.   currdir = directory()
  33.   newdir = directory(image_dir)
  34.   call directory currdir
  35.   if newdir <> image_dir then
  36.   do
  37.     call rxfuncadd 'sysmkdir','rexxutil','sysmkdir'
  38.     rc = SysMkDir(image_dir)
  39.     if rc <> 0 then call Usage("Could not create directory "image_dir)
  40.   end
  41.   image_dir = image_dir || '\DISK'
  42. end
  43. parms = parms ' ' rest
  44. if words(parms) > 2  then call Usage
  45. image_name = word(parms,1)
  46. num_images = word(parms,2)
  47. if image_name = '?' then call Usage
  48. if num_images > '' & datatype(num_images) <> 'NUM' then call Usage
  49. if pos('?',image_name) = 0 then call Usage("Image file name must contain a '?'")
  50. parse var image_name begin_name'?'end_name
  51. if num_images = '' then
  52. do
  53.   do num_images = start_disk by 1
  54.     if stream(begin_name || num_images || end_name,'Command','Query Exists') = ''
  55.     then leave
  56.   end
  57.   num_images = num_images - start_disk
  58. end
  59. last_disk = start_disk + num_images - 1
  60. do n = start_disk to last_disk
  61.   fname = begin_name || n || end_name
  62.   if stream(fname,'Command','Query Exists') = ''
  63.   then do
  64.           call Usage("File, "fname", does not exists!")
  65.        end
  66. end
  67. say 'Will copy 'begin_name || start_disk || end_name' thru 'begin_name || last_disk || end_name
  68. do n = start_disk to last_disk
  69.  if image_dir = '' then do
  70.    say ''
  71.    say 'Insert diskette #'n', hit any key to continue...'
  72.    pull
  73.  end
  74.  else say 'Creating diskette image #'n
  75.  command = 'loaddskf 'begin_name || n || end_name ' a: /F /Y'
  76.  if debug = TRUE then say command
  77.                  else command
  78.  if image_dir > '' then
  79.  do
  80.    if n < 10 then dirnum = '0'n
  81.              else dirnum = n
  82.    target_dir = image_dir || dirnum
  83.    say 'Creating directory 'target_dir
  84.    if debug = FALSE
  85.    then call SysMkDir target_dir
  86.    command = 'xcopy a:*.* 'target_dir '/S'
  87.    if debug = TRUE then say command
  88.                    else command
  89.  end
  90. end
  91. return
  92.  
  93. Usage:procedure
  94. parse arg message
  95.  
  96.   say '**********************************************************************'
  97.   say ' 'd2c(7)
  98.   if message > "" then do
  99.     say message
  100.     say ""
  101.   end
  102.   say "Usage: makeimg imagefile_name | number_of_images | | options |"
  103.   say 'Where: imagefile_name is in the format name_part_1 + ? |+ name_part_2 |'
  104.   say "       The '?' denotes the position in the file name that contains an "
  105.   say "       incrementing value"
  106.   say "       "
  107.   say "       If number_of_images is not specified then the program will use all"
  108.   say "       valid matches for the file name."
  109.   say "Options:"
  110.   say "        /Sn = Start Disk "
  111.   say "        /Ip = Create images at root path p (e.g. /Ic:\img)"
  112.   say "        /T  = Run in test mode. Do not copy any files. Report only."
  113.   say ""
  114.   say "Example: makeimg us8049_?.img 7"
  115.   say "         will create 7 images starting with us8049_1.img -> us8049_7.img"
  116.   exit
  117.  
  118.