Help needed to copy files 
Author Message
 Help needed to copy files

Hi!
I am  beginner in Perl and I have a little problem.
Please help me with the piece of code to copy many files to one.
Something like: File1.txt + File2.txt + File3.txt = newFile.txt
I can do it under MS-DOS:

copy *.txt newFile.txt

This command is in my .bat file and it works fine.
With Best Regards,
Janek.



Wed, 18 Jun 1902 08:00:00 GMT  
 Help needed to copy files

Quote:

>I am  beginner in Perl and I have a little problem.
>Please help me with the piece of code to copy many files to one.
>Something like: File1.txt + File2.txt + File3.txt = newFile.txt
>I can do it under MS-DOS:

>copy *.txt newFile.txt

Open a file for writing. Open each of the files to copy and print them to
the filehandle of the file opened for writing.

  #!/usr/local/bin/perl -w

  open N, ">newFile.txt" or die "Can't open newFile.txt: $!\n";

  while ($file = <DATA>) {
      chomp $file;
      open F, $file or die "Can't open $file: $!\n";
      while (<F>) {
          print N;
      }
  }

  close N;
  close F;

  __DATA__
  File1.txt
  File2.txt
  File3.txt

Result:

  $ wc -l File*
       44 File1.txt
       90 File2.txt
      138 File3.txt
      272 total

  $ wc -l new*
      272 newFile.txt

--

DIARY, n. A daily record of that part of one's life, which he can relate
to himself without blushing.
- Ambrose Bierce



Wed, 18 Jun 1902 08:00:00 GMT  
 Help needed to copy files
: Hi!
: I am  beginner in Perl and I have a little problem.
: Please help me with the piece of code to copy many files to one.
: Something like: File1.txt + File2.txt + File3.txt = newFile.txt
: I can do it under MS-DOS:

: copy *.txt newFile.txt

        perl -pe'BEGIN{open STDOUT,">".pop}' *.txt newFile.txt

Joy,
Yanick

--
($_,$y)=('Yhre lo  .kePnarhtretcae',     '(.) (.)');

                                      #    `---'



Wed, 18 Jun 1902 08:00:00 GMT  
 Help needed to copy files

<URL::">
`' Hi!
`' I am  beginner in Perl and I have a little problem.
`' Please help me with the piece of code to copy many files to one.
`' Something like: File1.txt + File2.txt + File3.txt = newFile.txt
`' I can do it under MS-DOS:
`'
`' copy *.txt newFile.txt
`'
`' This command is in my .bat file and it works fine.

Then why the need to change?

    system 'copy *.txt newFile.txt';

Abigail
--
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help needed to copy files

2. Help needed to copy files

3. File::Copy help needed

4. Using File::Copy and Sockets to copy public files from http addresses

5. File::Copy, copying files problem.

6. Need help on some copy program

7. Warning using copy from File::Copy

8. Semantics of File::Copy::copy(,)

9. Seek Help for copying binary files

10. Help with opening and copying to a file

11. Newbie help: copying files

12. Copying an exec file!!HELP!!

 

 
Powered by phpBB® Forum Software