home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / diskin16.zip / diskin.CMD next >
OS/2 REXX Batch file  |  2002-07-16  |  9KB  |  228 lines

  1. /* REXX * DISKIN ************************************************************/
  2. /* Zweck...: Kopiert den Inhalt einer Digicam-Disk in ein Incoming-Verz.    */
  3. /*           Dabei erhält der Filename eine fortlaufende Nummer             */
  4. /* Autor...: M. Dort (matthias.dort@epost.de)                               */
  5. /*         : C. Beck (christian.beck11@epost.de)                            */
  6. /* Date....: 8.7.2002                                                       */
  7. vers = "1.6"                                             /* Programmversion */
  8. /****************************************************************************/
  9.  
  10. /*****************************************************************************/
  11. /* History:                                                                  */
  12. /* V 1.0 - Original                                                          */
  13. /* V 1.1 - Prüfen, ob Quell UND Zielvereichnis bereit. Sonst Abbruch         */
  14. /*         Verwendung von verschiedenen Extensions                           */
  15. /*         Löschvorgang am Ende ohne Interaktion                             */
  16. /* V 1.2 - Abfangen wenn fehlerhaft kopiert wird von Quell nach Ziellaufwerk */
  17. /* V 1.3 - Ausgabe Erste letzte Nummer korrigiert /md                        */
  18. /* V 1.4 - Vorbelegen der Variable "weiter" mit "J" zum automatischen Löschen*/
  19. /*         Dateizähler macht führende 0000                                   */
  20. /* V 1.5 - Ausgabe über kopierte Dateien noch mal geändert.                  */
  21. /*       - Funktion zum Auffüllen mit 0 eingeführt                           */
  22. /* V 1.6 - Kommentare angepasst. Ausgaben Letzte Nummer, Es wurden insges..  */
  23. /*         am Programende getauscht                                          */
  24. /*****************************************************************************/
  25.  
  26. /*****************************************************************************/
  27. /* ToDo:                                                                     */
  28. /* momentan nix                                                              */
  29. /*****************************************************************************/
  30.  
  31. /*****************************************************************************/
  32. /* Ab hier bitte Variablen anpassen                                          */
  33. /* --------------------------------                                          */
  34. /* Quell-Laufwerk und Zielpfad (Incoming-Verzeichnis) definieren             */
  35. /* Welche Dateiendungen sollen kopiert werden                                */
  36. /*diskLW="e:\temp\diskin\diskette"         Becki-Test   */
  37. /*incomingLW="e:\temp\diskin\platte"       Becki-Test   */
  38.  
  39. diskLW="g:\temp"                        /* Math-Test   */
  40. incomingLW="g:\incom"                   /* Math-Test   */
  41. /*****************************************************************************/
  42.  
  43. /* Hier werden die Extensions der Dateien eingetragen                        */
  44. /* Wenn die eine oder andere hinzugefügt oder wegenommen wird, nicht         */
  45. /* vergessen ext.0 entsprechend anzupassen !!!                               */
  46. ext.0 = 3
  47. ext.1 = "jpg"
  48. ext.2 = "gif"
  49. ext.3 = "mpeg"
  50. /*****************************************************************************/
  51.  
  52. echo off
  53. ARG parm .
  54.  
  55. /* for the test of the drive and SysFileDelete */
  56. call rxfuncadd 'sysLoadFuncs', 'rexxutil', 'sysloadfuncs'
  57. call sysloadfuncs
  58.  
  59. if (parm == "--HELP") | (parm == "-H") then do
  60.  
  61. /* Intro-Screen */
  62.  
  63.   say
  64.   say "                        **********************"
  65.   say "                        * - -  DISKIN  - - - *"
  66.   say "                        *     ver. "vers "      *"
  67.   say "                        **********************"
  68.   say
  69.   say "     Copies the content of a Digicam disc in an import directory"
  70.   say "     There the file name has a increasing number"
  71.   say
  72.   say "     call diskin"
  73.   say
  74.   say "     (c) M. Dort, matthias.dort@epost.de"
  75.   say "     (c) C. Beck, christian.beck11@epost.de"
  76. exit
  77. end
  78.  
  79. else do
  80.  
  81.   say
  82.     say "diskin [--help]"
  83.    say
  84.  
  85. end
  86.  
  87.  
  88. /* test whether source drive is ready */
  89. lw = substr(diskLW,1,2)
  90. zeile = SysDriveInfo(lw)
  91. if zeile == "" then
  92.  do
  93.    say 'source drive 'lw' is not ready'
  94.    say 'is there a discette within the drive ??)'
  95.    exit
  96.  end
  97. else
  98.  do
  99.    parse var zeile  . . . name
  100.    say 'source drive 'lw' has the name: "'strip(name)'"'
  101.  end
  102.  
  103. /* test whether the target drive is ready */
  104. lw = substr(incomingLW,1,2)
  105. zeile = SysDriveInfo(lw)
  106. if zeile == "" then
  107.  do
  108.    say 'source drive 'lw' is  not ready'
  109.    say '(no diskette put in ??)'
  110.    exit
  111.  end
  112. else
  113.  do
  114.    parse var zeile  . . . name
  115.    say 'source drive 'lw' has the name: "'strip(name)'"'
  116.  end
  117.  
  118. /* temporary files should be erased */
  119. "if exist "incomingLW"\*.tmp del "incomingLW"\*.tmp"
  120.  
  121. /* the counting file will be created if there is no one */
  122.  rc = lines(incomingLW"\zaehler")
  123.  
  124. if rc = 0 then do
  125.   tmp = lineout(incomingLW"\zaehler","00000",1)
  126. end
  127.  
  128. /* counting index to read */
  129. x = stream(incomingLW'\zaehler','c','close') /* this option allows new write accesses  */
  130. fileindex=linein(incomingLW"\zaehler")
  131.  
  132. /* file index for later calculation saved */
  133. fileindexalt=fileindex
  134. /* information for the user       */
  135. say "First new number is "fileindexalt
  136.  
  137. /* test whether files exist with correct extension on the medium */
  138. /* if yes with comamd dir the names move in a temporary file within incoming directory */
  139. /* the switcher "/f" works that only the files name with the path are shown */
  140. do i = 1 to ext.0
  141.   "if exist "diskLW"\*."ext.i "dir "diskLW"\*."ext.i" /f >> "incomingLW"\files.tmp"
  142. end
  143.  
  144. /* the main program */
  145. /* temporary file completly read, for each line one copy oder */
  146. /* conunt index increased */
  147. do while lines(incomingLW"\files.tmp") > 0
  148.   filename = linein(incomingLW"\files.tmp")
  149.   l = length(filename)
  150.   p = lastpos('.',filename)
  151.   endung = substr(filename,p+1,l-p)
  152.   filename_neu = fileindex"."endung
  153.  
  154.   "copy "filename incomingLW"\"filename_neu
  155.    if rc > 0 then
  156.    do
  157.      say 'Error during copy of 'filename' to 'incomingLW'\'filename_neu
  158.      say 'Returncode = 'rc
  159.      say 'program has finished'
  160.      exit
  161.    end
  162.    rc = sysfiledelete(filename)
  163.    if rc > 0 then
  164.    do
  165.      say 'the original file on the source facility ('filename')'
  166.      say 'impossible to delete RC = 'rc
  167.      say '   2              Error. File not found '
  168.      say '   3              Error. Path not found '
  169.      say '   5              Error. Access refused '
  170.      say '   26             Error. No DOS data facility'
  171.      say '   32             Error. Confilct during common access '
  172.      say '   36             Error. Overflow of the buffer for the common access '
  173.      say '   87             Error. Inavlid parameter '
  174.      say '   206            Error. File name or file extension to long'
  175.    end
  176.  
  177.    /* increase teh counter by 1 */
  178.   fileindex = fileindex + 1
  179.   fileindex = auffuellen(fileindex)
  180. end
  181.  
  182. /* write back the couinting level into the fist line */
  183. tmp = lineout(incomingLW"\"zaehler,fileindex,1)
  184.  
  185. /* Only if any action happened, user will be informed about last copied file */
  186. if fileindex-fileindexalt \== 0 then do
  187.   fileindex=fileindex-1
  188.   fileindex = auffuellen(fileindex)
  189.   say "last new number is  "fileindex
  190.   fileindex = fileindex+1
  191. end
  192.  
  193. /* Total number of copied files   */
  194. say "There were totally  "fileindex-fileindexalt " files copied."
  195.  
  196. /* delete temporary file */
  197. x = stream(incomingLW'\files.tmp','c','close') /* so further write oders are possibel */
  198. "if exist "incomingLW"\*.tmp del "incomingLW"\*.tmp"
  199.  
  200. say "source drive "diskLW" can be erased"
  201.  
  202. /* delete diskette  */
  203. /* the Sony-Mavica puts always for each image file a hidden file */
  204. /* therefore the attributes are set back */
  205.  
  206. say diskLW " delete ? j/n (J)"
  207.   pull weiter      /* store it */
  208.   if (weiter = "J") | (weiter = "") then
  209.    do
  210.     "if exist "diskLW"\*" attrib diskLw"\* -h -r -s"
  211.     "if exist "diskLW"\*" del diskLw"\* /N"
  212.      say "to late : all the files are off"
  213.    end
  214.  
  215. return 0
  216.  
  217. /* Function to fill the file index with 0. Always with 5 digits */
  218. /* so the list can be better read */
  219.  
  220. auffuellen:
  221.   arg variable
  222.   /* for the best view of the user */
  223.   if (variable > 0) & (variable < 10) then variable = '0000'variable
  224.   if (variable > 9) & (variable < 100) then variable = '000'variable
  225.   if (variable > 99) & (variable < 1000) then variable = '00'variable
  226.   if (variable > 999) & (variable < 10000) then variable = '0'variable
  227. return variable
  228.