[Vienna-pm] Datei binär kopieren (unter Windows)

Peter Seitz seitz at bzs.tu-graz.ac.at
Mon Jun 2 15:45:21 CDT 2003


Hallo Gruppe,

ich möchte eine (Grafik-)Datei binär kopieren. Da ich nicht weiß, ob
mein Programm unter Linux oder unter Windows ausgeführt wird möchte
ich es Betriebssystemunabhängig machen. Mein code unter ActiveState
Perl und Windows 98:

sub binarycopy {
# copy binary files
  ($input,$output) = @_;
  my $buf;
  my $len;

  if (-e $input) {
    open (INPUT, $input) ||
      die "Can't Open Input File $input: $!\n";
    binmode (INPUT);
    print "\t$input... ";

    if (not -e $output) {
      open (OUTPUT, ">$output") ||
        die "Can't Open Output File $output: $!\n";

      while ($len=sysread(INPUT, $buf, 1024)) {
        print OUTPUT $buf;
      }
      print "done\n";
      close (OUTPUT);
    } else {
      print "does already exist - not copied\n";
      }
    close (INPUT);
  }
} ## sub binarycopy


Einige Dateien werden sauber kopiert, andere jedoch sind zerstört.
Sie haben eine unterschiedliche Länge.

Aus dem Programming perl werde ich nicht weiter schlau. Obiges
Beispiel soll im Perl cookbook zu finden sein, aber das habe ich
leider noch nicht :-{

Was mache ich falsch? Ist es sinnvoll die Dateigröße festzustellen und
dann in einem Schubs die Datei zu lesen? Das könnte aber IMHO bei
sehr großen Dateien das Programm auch zum Absturz bringen, oder?

Etwas ratlos...


With best compliments

           Peter Seitz
--

  Graz University of Technology, Austria - Fac. f. Civil Engineering
  mailto:seitz at bzs.tu-graz.ac.at - http://wwwbzs.tu-graz.ac.at/~seitz/

            Member of the Pegasus Mail Support Group
          Coordinator of the Pmail Translation Process

For information about translating Pegasus Mail, contact:
Han van den Bogaerde or Peter Seitz at
translation-coordinator at pmail.gen.nz



More information about the Vienna-pm mailing list