home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / edit / sidconverter / convertsid.rexx < prev    next >
OS/2 REXX Batch file  |  1994-09-03  |  5KB  |  164 lines

  1. /*************************************************************************/
  2. /*              SIDPLAYER file conversion script V1.0b                   */
  3. /*                Written by David Poland on 9/1/94                      */
  4. /*************************************************************************/
  5.  
  6. /* Please note that this script requires "rexxsupport.library" in the
  7.    libs directory */
  8.  
  9. /* Change the prompt for input from shell */
  10.  
  11. options prompt '> '
  12.  
  13. /* If the library is not already loaded into memory then do so.  Then we
  14.    check to see if the library is available.  If it is, load it up, if not
  15.    report the error. */
  16.  
  17. if ~show('L', "rexxsupport.library") then do
  18.     if addlib('rexxsupport.library',0,-30,0) then
  19.         say "Added rexxsupport.library"
  20.     else do
  21.         say "ERROR! Rexxsupport.library is required for this script."
  22.         exit 10
  23.     end
  24. end
  25.  
  26.  
  27. /* Announce who we are :-) */
  28.  
  29. say ""
  30. say "* ConvertSID arexx script V1.0b *"
  31.  
  32. /* Get the current directory we are in */
  33.  
  34. CurrentPath = pragma('D')
  35.  
  36. /* Now get the destination directory where we will send the converted
  37.    files to */
  38.  
  39. GetDestDir(DestDir,CurrentPath)
  40.  
  41. /* Assign the filenames (excluding subdirs etc) to a variable */
  42.  
  43. FileList = showdir(CurrentPath, 'f', ':')
  44.  
  45. /*************************************************************************/
  46. /* Now process all the filenames in the FileList                         */
  47. /*************************************************************************/
  48.  
  49. ExitLoop = 0     /* Init our Boolean flag to FALSE */
  50. FileNumber = 0   /* Number of files converted */
  51.  
  52. /* While ExitLoop is not equal to TRUE, keep looping */
  53.  
  54.  
  55. say ""
  56. say "File conversion in process..."
  57.  
  58. do while ExitLoop ~= 1
  59.  
  60.     /* Each filename is separated by a colon as specified by the pragma
  61.        command earlier.  Find the position of the first colon */
  62.  
  63.     Position = index(FileList, ":")
  64.  
  65.     /* Now if no colon was found, we are done and exit the loop.
  66.        If a colon was found, we need to extract the filename from
  67.        the list and assign it to "FileName".  Then we'll need to remove
  68.        the filename from the list so we use DelStr to remove it. */
  69.     
  70.     if Position > 0 then do
  71.         FileName = Left(FileList,Position-1)
  72.         ConvertFile(pad)
  73.         FileList = delstr(FileList,1,Position)
  74.     end 
  75.     else do
  76.         /* Here we need to check and see if only ONE filename is in the
  77.            FileList and to process it if this is so. */
  78.  
  79.         if length(FileList) ~= 0 then do
  80.             FileLength = Length(FileList)
  81.             FileName = Left(FileList,FileLength)
  82.             ConvertFile(pad)   
  83.             FileList = ""
  84.         end
  85.         else 
  86.             ExitLoop = 1
  87.     end
  88.  
  89. end /*DO*/
  90.  
  91. say ""
  92. say "File conversion completed!  " || FileNumber || " files converted."
  93. say ""
  94.  
  95. exit
  96.  
  97. /*************************************************************************/
  98. /* Procedure to handle the actual file conversion                        */
  99. /*************************************************************************/
  100.  
  101. ConvertFile:
  102.  
  103.     arg pad /* Can't call a function without an arg so we provide a dummy */
  104.  
  105.     InfoString = ".info"
  106.  
  107.     /* Check to see if we have an Icon file */
  108.  
  109.     InfoFlag = pos(upper(InfoString),upper(FileName))
  110.  
  111.     if InfoFlag ~= 0 then do
  112.         NewFileName = left(FileName,length(FileName)-5) /*Strip .info off*/
  113.         address command "sid:sidconv " || """" || NewFileName || """" ||,
  114.                         " " || DestDir || "/" || space(NewFileName,0)
  115.         FileNumber = FileNumber + 1
  116.     end
  117.   
  118. return 0
  119.  
  120. /*************************************************************************/
  121. /* Procedure to handle destination directory                             */
  122. /*************************************************************************/
  123.  
  124. GetDestDir:
  125.  
  126.     arg DestDir, CurrentPath
  127.  
  128.     say ""
  129.     say "Please enter the path for the destination of the converted files."
  130.     say "NOTE!!! Do not select the current directory as the destination or"
  131.     say "your original files will be overwritten!!!"
  132.     say ""
  133.     say "Current directory path is: " || CurrentPath
  134.     say ""
  135.  
  136.     pull DestDir
  137.  
  138.     /* Strip off a "/" on the end if the user added one. */
  139.  
  140.     if pos("/",DestDir,length(DestDir)) ~= 0 then
  141.         DestDir = left(DestDir,Length(DestDir)-1)
  142.  
  143.     /* Check to see if the selected destination directory exists, if
  144.        it does, then continue on, if not ask if they want to create it */
  145.  
  146.     if ~exists(DestDir) then do
  147.         say ""
  148.         say "The selected destination directory does not exist.  Shall I"
  149.         say "create it for you? (Y/N)"
  150.         pull Answer
  151.  
  152.         if Answer = "Y" then do
  153.             address command "makedir " || DestDir
  154.             say "Directory " || DestDir || " has been created."
  155.         end
  156.         else do
  157.             say "Directory not created - script aborted."
  158.             exit
  159.         end
  160.  
  161.     end
  162.          
  163. return DestDir
  164.