Solved

Problems copy file from CD using Block Read - Access Denied

Posted on 2006-11-13
3
767 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now