Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with file management

Status
Not open for further replies.

yelimeli

Programmer
Jun 6, 2000
10
US
Hey<br><br>&nbsp;&nbsp;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. <br><br>The following is the code is what i tried :<br><br><br>$file='c:\abc.doc';<br>$out='c:\abc3.doc';<br>open(FILE,$file)¦¦die(&quot;Error opening file $!&quot;);<br>open(OUT,&quot;&gt;$out&quot;)¦¦die(&quot;Error opening outfile $!&quot;);<br>$size=(-s $file);<br>sysread(FILE,$string,$i);<br>syswrite(OUT,$string,$i);<br>close(FILE);<br>close(OUT);<br><br>but when i open abc3.doc which is the output file nothing is there.&nbsp;&nbsp;Thanks for your time and i hope i will get some reply soon.<br><br>Thanks & Regards<br>Srinivas<br><br><br><br><br>
 
What value does the syswrite function return? It's supposed to return the number of bytes written or undef if there was a problem.<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>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?"
 
' Looks like&nbsp;&nbsp;you may be specifying read and write lengths of null. <br>The third arg &quot;$i&quot; foreach, the length, is not set.&nbsp;&nbsp;<br>Maybe you meant to put $size there?
 
ouch!<br><br>goBoating is right -- I should retire to the Basket Weaver Anonymous (for Beginners) forum I think <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>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?"
 
Hey<br><br>&nbsp;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. <br><br>Thanks & Regards<br>Srinivas Yelimeli<br><br>
 
I tried using <i>sysread</i> and <i>syswrite</i> on a WORD doc and had the same trouble.&nbsp;&nbsp;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.......<br><br>I wonder if the <i>size</i> returned by the '-s' file test is in blocks or k or something other than bytes....???<br><br>If you are simply trying to duplicate the file, why don't you just do that.<br><br><i>$file1 = 'someText.doc';<br>$file2 = 'anotherName.doc';</i><br># inside backticks.....<br><i>`copy $file1 $file2`;</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# copy for Windows<br><b>OR</b><br><i>`cp $file1 $file2`;</i> &nbsp;&nbsp;&nbsp;&nbsp;# cp for UNIX<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top