Solved

Problems copy file from CD using Block Read - Access Denied

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

790 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