×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

help with file management

help with file management

help with file management

(OP)
Hey

  I'm writing a program to read a word document and copy it to another word document. But when i open the file created i get some strange characters.

The following is the code is what i tried :


$file='c:\abc.doc';
$out='c:\abc3.doc';
open(FILE,$file)¦¦die("Error opening file $!");
open(OUT,">$out")¦¦die("Error opening outfile $!");
$size=(-s $file);
sysread(FILE,$string,$i);
syswrite(OUT,$string,$i);
close(FILE);
close(OUT);

but when i open abc3.doc which is the output file nothing is there.  Thanks for your time and i hope i will get some reply soon.

Thanks & Regards
Srinivas




RE: help with file management

What value does the syswrite function return? It's supposed to return the number of bytes written or undef if there was a problem.

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site
Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"

RE: help with file management

' Looks like  you may be specifying read and write lengths of null.
The third arg "$i" foreach, the length, is not set.  
Maybe you meant to put $size there?

RE: help with file management

ouch!

goBoating is right -- I should retire to the Basket Weaver Anonymous (for Beginners) forum I think

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site
Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"

RE: help with file management

(OP)
Hey

 You are right. I did use $size, but it was of no use. the output file still had nothing. Please help me, let me know how i can open a file in MS-word copy the contents to another doc file and print it. The above code i tried seems correct please let me know what is wrong. I greatly appreciate the time you are devoting to this task.

Thanks & Regards
Srinivas Yelimeli

RE: help with file management

I tried using sysread and syswrite on a WORD doc and had the same trouble.  The problem is not in the write, it is in the read......I don't have time to play with it any more right now.......

I wonder if the size returned by the '-s' file test is in blocks or k or something other than bytes....???

If you are simply trying to duplicate the file, why don't you just do that.

$file1 = 'someText.doc';
$file2 = 'anotherName.doc';

# inside backticks.....
`copy $file1 $file2`;     # copy for Windows
OR
`cp $file1 $file2`;     # cp for UNIX

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close