identification division.
program-id. filelist.
environment division.
configuration section.
special-names.
    decimal-point is comma.
input-output section.
file-control.
     select s1-datei assign to disk "dateilist.dat"
     organization line sequential.
data division.
file section.
fd s1-datei.
01 s1-satz.
   03 s1-name     pic x(50).
   03 s1-size     pic zzz.zzz.zzz.999.
   03 s1-text redefines s1-size pic x(15).
   03             pic xx.
   03 s1-datum    pic 9999.99.99.
WORKING-STORAGE SECTION.
copy "acucobol.def".
01  pattern       pic x(5) value "*".
01  dateiname     pic x(50).
01  directory     pic x(50) value "d:\eigene\strato\".
01  filename      pic x(128).
01  mydir         usage handle.
01  w-summe       pic 9(12).
01.
    03 occurs 1000.
       05 w-name  pic x(50).
       05 w-size  pic 9(9).
       05 w-datum pic 9(8).
77 z-l  pic 9(4).
77 status-code  pic 99.
01  FILE-INFO.
    02  FILE-SIZE    PIC X(8) COMP-X.
    02  FILE-DATE    PIC 9(8) COMP-X.
    02  FILE-TIME    PIC 9(8) COMP-X.

PROCEDURE DIVISION.
MAIN.
    perform verzeichnis-pruefen
    perform verzeichnis-lesen
    perform datei-schreiben
    perform ende.

verzeichnis-pruefen.
    display "Verzeichnis ->" at 0201
    accept directory at 0216 prompt tab
    call "C$LIST-DIRECTORY" using listdir-open, directory, pattern.
    move return-code to mydir.
    if mydir = 0
       perform ende
    end-if.

verzeichnis-lesen.
    move 1 to z-l
    perform with test after until filename = spaces or z-l > 1000
       call "C$LIST-DIRECTORY" using listdir-next, mydir, filename
       display filename
       move filename to w-name(z-l)
       initialize dateiname
       string directory filename delimited by space into dateiname
       CALL "C$FILEINFO" 
           USING dateiname, FILE-INFO, 
           GIVING STATUS-CODE
       move file-size to w-size(z-l)
       move file-date to w-datum(z-l)
       add 1 to z-l
    end-perform.

datei-schreiben.
    call "C$LIST-DIRECTORY" using listdir-close, mydir.
    initialize w-summe
     open output s1-datei
    perform varying z-l from 1 by 1 until z-l > 1000
       if w-name(z-l) not = space
          move w-name(z-l) to s1-name
          if w-datum (z-l)(1:4) > "3000"
             move "verzeichnis" to s1-text
             initialize s1-datum
          else
             move w-size(z-l) to s1-size
             move w-datum(z-l) to s1-datum
             compute w-summe = w-summe + w-size(z-l)
          end-if
          write s1-satz
       else
          move 1001 to z-l
       end-if
    end-perform
    initialize s1-satz
    move "Summe" to s1-name
    move w-summe to s1-size
    write s1-satz
    close s1-datei.

ende.
    exit program
    stop run.




