Solved

Problems copy file from CD using Block Read - Access Denied

Posted on 2006-11-13
3
770 Views
Last Modified: 2009-12-16
I have written an install program, which gets a destination path from a user and then copies a database (mdb) file from a CD to the destination.

The install program works when I test it from the hard disk, but when I burnt it to a CD and went to test it, the database file was not copied.

I put some dialogs to show me what was happening, and I get an error msg re: Access Denied

Code below

=====================
var
  FromF, ToF : file of byte;
  Buffer : array[ 0..4096 ] of char;
  NumRead : integer;
  FileLength : longint;

begin
  try
   AssignFile( FromF, Source );
   filemode := fmOpenReadWrite;
   Reset( FromF );
   AssignFile( ToF, Destination);
   Rewrite( ToF );
   FileLength := FileSize( FromF );

      while FileLength > 0 do begin
        BlockRead( FromF, Buffer[ 0 ], SizeOf( Buffer ), NumRead );
        FileLength := FileLength - NumRead;
        BlockWrite( ToF, Buffer[ 0 ], NumRead );
        Position := Position + NumRead;
      end;
 
   CloseFile( FromF );
   CloseFile( ToF );
  except
        on e: Exception do
              MessageDlg('Error :'+e.Message, mtError, [mbOK], 0);
  end;  // try/except
end;
0
Comment
Question by:pjelias
  • 2
3 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17930518
Your code:

   filemode := fmOpenReadWrite;
   Reset( FromF );


opens the source file in read / write mode, which is not possible on a RO (readonly) media. It really should be:

   filemode := fmOpenRead;
   Reset( FromF );


---------

Russell
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
ID: 17930626
Btw, you could also just use the CopyFile routine in windows:

 if not(CopyFile(PChar(Source), PChar(Destination), False)) then
 begin
    // GetLastError will contain the error code
    ShowMessage(SysErrorMessage(GetLastError));
 end;

---

Russell
0
 

Author Comment

by:pjelias
ID: 17933487
Of course, hard to see the simple things at 2:30am.

Also need to set the File Attributes so that file is not read only.

Thanks for your help

Regards
pje
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question