home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / infocoll.zip / InfoColl.CMD
OS/2 REXX Batch file  |  1999-07-21  |  12KB  |  226 lines

  1. /* INFOCOLL - Searches system drive(s) for .HLP and .INF files
  2.    and creates program objects for them in a destination folder
  3.  
  4.    Use it if you like it. Don't if you don't. No legalese.
  5.  
  6.    (c) 1999 Marcus de Geus
  7.             marcus@degeus.com
  8.             http://www.degeus.com
  9.  
  10.    ***************************************************************/
  11.  
  12. signal on Halt                                                           /* handle halt condition */
  13.  
  14. say 'This program searches one or more system drives for .HLP and .INF'  /* info */
  15. say 'files and for each file found creates a VIEW.EXE program object'    /* info */
  16. say 'in a destination folder.'                                           /* info */
  17. say ''                                                                   /* empty line */
  18.  
  19. if (\LoadREXXUtils()) then                                               /* if we cannot load the REXX utilities */
  20. do
  21.  call Halt                                                               /* quit */
  22. end
  23.  
  24. say 'Drive(s) to search (separate with spaces):'                         /* info */
  25. parse pull DrivesInput                                                   /* get a list of drives to search */
  26.  
  27. if (DrivesInput = '') then                                               /* if we have no drives to search */
  28. do
  29.  call Halt                                                               /* just quit */
  30. end
  31.  
  32. DriveMap = sysdrivemap(,'USED')                                          /* get a list of all the drives currently in use */
  33. DriveList = ''                                                           /* start with nothing */
  34.  
  35. do words(DrivesInput)                                                    /* for each of the drives requested */
  36.  parse var DrivesInput OneDrive DrivesInput                              /* get the drive name */
  37.  OneDrive = translate(strip(OneDrive,'T',':'))||':'                      /* reshape it into an uppercase word followed by one colon */
  38.  if (pos(OneDrive,DriveMap) = 0) then                                    /* if it is not in the official list */
  39.  do
  40.   call beep 333,333                                                      /* signal */
  41.   say OneDrive||' is not a valid drive'                                  /* report */
  42.   call Halt                                                              /* and quit */
  43.  end
  44.  else                                                                    /* if it is in the list */
  45.  do
  46.   DriveList = DriveList||' '||OneDrive                                   /* add it to our own list */
  47.  end
  48. end
  49.  
  50. Destination = GetLoc('Enter the name of the destination folder:')        /* get the destination folder */
  51.  
  52. if (Destination = '') then                                               /* if we have no destination */
  53. do
  54.  call beep 333,333                                                       /* signal */
  55.  call Halt                                                               /* just quit */
  56. end
  57.  
  58. if (words(DriveList) > 1) then                                           /* if we have more than one drive */
  59. do
  60.  Plural = 's'                                                            /* we need a plural "s" */
  61. end
  62. else                                                                     /* if we have only one drive to search */
  63. do
  64.  Plural = ''                                                             /* we don't need the extra "s" */
  65. end
  66. say ''                                                                   /* empty line */
  67. say 'Drive'||Plural||' to search:'||DriveList                            /* report */
  68. say 'Destination = '||Destination                                        /* report */
  69. say ''                                                                   /* empty line */
  70.  
  71. Count = 0                                                                /* reset the counter */
  72. do words(DriveList)                                                      /* for each drive in the list */
  73.  parse var DriveList Drive DriveList                                     /* get the next drive */
  74.  Count = Count + CollectInfo(Drive,Destination,'HLP')                    /* look for HLP files*/
  75.  Count = Count + CollectInfo(Drive,Destination,'INF')                    /* and look for INF files */
  76. end
  77.  
  78. say ''                                                                   /* empty line */
  79. say Count||' program objects created in '||Destination                   /* report */
  80.  
  81. call Halt                                                                /* that's all, folks! */
  82.  
  83.  
  84.  
  85. /***************************************************************/
  86.  
  87. CollectInfo: procedure                                                   /* does the actual collecting */
  88.  
  89. parse arg Drive,Destination,FileType                                     /* get the arguments */
  90.  
  91. say 'Looking for '||FileType||' files on '||Drive                        /* report */
  92.  
  93. Counter = 0                                                              /* reset the counter */
  94. call sysfiletree Drive||'\*.'||FileType,'Files.','FOS'                   /* look for the files in the root and subdirectories */
  95.  
  96. do Index = 1 to Files.0                                                  /* for each of the files in filespec, do */
  97.  
  98.  ObjectTitle = ''                                                        /* clear object title */
  99.  
  100.  call stream Files.Index,'C','OPEN READ'                                 /* open the source file for reading */
  101.  Input = CharIn(Files.Index,1,3)                                         /* get the first three bytes */
  102.  
  103.  If (Input = 'HSP') then                                                 /* if it is a HLP or INF file */
  104.  do
  105.   Position = 108                                                         /* this is where the file title should be in the file */
  106.   do while Position >< 0                                                 /* start moving through the file until Position gets set to 0 */
  107.    Input = CharIn(Files.Index,Position,1)                                /* read one character from the file */
  108.    If (C2D(Input) >< 0) then                                             /* as long as it is not a null byte */
  109.    do
  110.     ObjectTitle = ObjectTitle||Input                                     /* add it to the title */
  111.     Position = Position + 1                                              /* up the counter */
  112.    end
  113.    else                                                                  /* if we find a null byte */
  114.    do
  115.     Position = 0                                                         /* we're finished */
  116.    end
  117.   end
  118.  end
  119.  
  120.  call stream Files.Index,'C','CLOSE'                                     /* close the source file */
  121.  
  122.  if (ObjectTitle = '') then                                              /* If no title was found */
  123.  do
  124.   ObjectTitle = '_Untitled'                                              /* create a dummy title */
  125.  end
  126.  
  127.  ObjectTitle = ObjectTitle||d2c(10)||'('||Files.Index||')'               /* add the file path on a separate line to complete the title */
  128.  Params = 'EXENAME=VIEW.EXE;PARAMETERS='||Files.Index||';'               /* the parameters to use for the program object */
  129.  
  130.  if (syscreateobject('WPProgram',ObjectTitle,Destination,Params)) then   /* if we can create a program object */
  131.  do
  132.   Counter = Counter + 1                                                  /* up the counter */
  133.  end
  134.  else                                                                    /* if we cannot create it */
  135.  do
  136.   say 'Cannot create program object for : '||Files.Index                 /* report */
  137.  end
  138.  
  139. end
  140.  
  141. say Counter||' '||FileType||' files found'                               /* report */
  142.  
  143. return Counter                                                           /* end of CollectInfo */
  144.  
  145.  
  146. /*****************************************************************/
  147.  
  148. GetLoc: procedure                                                        /* gets RexxMail destination folder */
  149.  
  150. parse arg Message                                                        /* get the message */
  151.  
  152. say Message                                                              /* report */
  153.  
  154. parse pull Location                                                      /* get the location*/
  155.  
  156. Location = strip(Location,'B',' ')                                       /* get rid of any leading and trailing blanks */
  157. Location = strip(Location,'T','\')                                       /* get rid of any trailing backslash */
  158. if (Location = '') then                                                  /* if we have nothing */
  159. do
  160.  say 'No location entered'                                               /* report */
  161.  return ''                                                               /* return empty */
  162. end
  163.  
  164. DriveLetter = filespec('D',Location)                                     /* get any drive letter from the new location */
  165. if (DriveLetter = '') then                                               /* if there is no drive letter */
  166. do
  167.  say 'The location must include a drive letter'                          /* report */
  168.  return ''                                                               /* return empty */
  169. end
  170.  
  171. call sysfiletree Location,'Loc.','DO'                                    /* look for the new location */
  172. if (Loc.0 = 0) then                                                      /* if it is not found */
  173. do
  174.  say '"'||Location||'" does not exist; should the folder be created?'    /* report */
  175.  say 'Type Y to confirm, any other key to abort; finish with [Enter]'    /* report */
  176.  parse upper pull Confirm                                                /* get a reply in upper case */
  177.  Confirm = strip(Confirm,'B',' ')                                        /* get rid of blanks */
  178.  if (substr(Confirm,1,1) >< 'Y') then                                    /* if it is not a yes */
  179.  do
  180.   return ''                                                              /* return empty */
  181.  end
  182.  
  183.  say 'Creating folder: '||Location                                       /* report */
  184.  if (sysmkdir(Location) >< 0) then                                       /* if we cannot create the new location folder */
  185.  do
  186.   say 'Cannot create '||Location                                         /* report */
  187.   return ''                                                              /* return empty */
  188.  end
  189.  
  190. end
  191.  
  192. return Location                                                          /* return with the new location */
  193.  
  194.  
  195. /***************************************************************/
  196.  
  197. LoadREXXUtils: procedure                                                 /* loads the REXX utilities library */
  198.  
  199. Result = 1                                                               /* start with a good result */
  200.  
  201. if rxfuncquery('SysLoadFuncs') then                                      /* if it is not already loaded */
  202. do
  203.  if (rxfuncadd('SysLoadFuncs','RexxUtil','SysLoadFuncs') >< 0) then      /* if we cannot add it */
  204.  do
  205.   call beep 333,333                                                      /* signal */
  206.   say 'Error : Cannot register Rexx Utilities library'                   /* report */
  207.   Result = 0                                                             /* bad result */
  208.  end
  209.  else                                                                    /* if we can add it */
  210.  do
  211.   if (SysLoadFuncs() = 0) then                                           /* if we cannot load it */
  212.   do
  213.    say 'Error : Cannot load Rexx Utilities library'                      /* report */
  214.    Result = 0                                                            /* bad result */
  215.   end
  216.  end
  217. end
  218.  
  219. return Result                                                            /* end of LoadREXXUtils */
  220.  
  221. /***************************************************************/
  222.  
  223. Halt:                                                                    /* handles halt condition */
  224.  
  225. exit                                                                     /* that's all, folks! */
  226.