Solved

Problems copy file from CD using Block Read - Access Denied

Posted on 2006-11-13
3
775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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