http://wiki.freepascal.org/mysql
I checked the readonly property of the files. The directory d:\multifilter was write-protected (I could not change this) but all files in it could be manipulated ad libitum.
So I checked if with inclusion of
Code: Pascal [Select]
- deletefile(d:\multifilter\b0.jpg);
Also
Code: Pascal [Select]
- files:='d:\multifilter\');
- deletefile(files+'b1.jpg');
Also
Code: Pascal [Select]
- files:='d:\multifilter\');
- n:=2;
- Str(n,nstring);
- fbstring:=files+'b'+nstring+'.jpg';
- deletefile(fbstring);
Also
Code: Pascal [Select]
- for n:=0 to nmax-1 do
- begin
- Str(n,nstring);
- fbstring:=files+'b'+nstring+'.jpg';
- deletefile(fbstring);
- end;
But the deletefile() directly before the savefile() (as discussed before) later on in the program does not work. Very rare! (The savefile() alone did not overwrite the old files - this was the cause of the whole problem).
So, I put the deletes at the first possible place (when it is clear if and how many files have to be deleted). And it works!
-------------
Example code : Try to delete a file twice |
var fileName : string; myFile : TextFile; data : string; begin // Try to open a text file for writing to fileName := 'Test.txt'; AssignFile(myFile, fileName); ReWrite(myFile); // Write to the file Write(myFile, 'Hello World'); // Close the file CloseFile(myFile); // Reopen the file in read mode Reset(myFile); // Display the file contents while not Eof(myFile) do begin ReadLn(myFile, data); ShowMessage(data); end; // Close the file for the last time CloseFile(myFile); // Now delete the file if deletefile(fileName) then ShowMessage(fileName+' deleted OK') else ShowMessage(fileName+' not deleted'); // Try to delete the file again if deletefile(fileName) then ShowMessage(fileName+' deleted OK again!') else ShowMessage(fileName+' not deleted, error = '+ IntToStr(GetLastError)); end; |
Show full unit code |
Hello World Test.txt deleted OK Test.txt not deleted, error = 2 |
No comments:
Post a Comment
Коментар: