Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
Klasör silme
#1
Merhaba,

Yaklaşık 3 önce aşağıdaki kodları kullanarak klasörü siliyordum fakat artık silmiyor ne neden olabilir?

function DeleteFile(const FileName: string): Boolean;
{$IFDEF MSWINDOWS}
begin
  Result := Winapi.Windows.DeleteFile(pChar(FileName));
end;
{$ENDIF MSWINDOWS}


procedure TMainForm.ButtonResetClick(Sender: TObject);
begin
    FDConnection.Connected := False;
    Winapi.Windows.DeleteFile(pChar('C:\Users\Hulya\Documents\PList'));
    MainForm := Nil;
    Application.Terminate; // Close
end;
Cevapla
#2
Dönen hata kodunu değerlendirmeli ve ona göre çözüm aramalısınız.

ref : MSDN 

Silebilmeniz için gereken şartlar ;
Alıntı:The following list identifies some tips for deleting, removing, or closing files:
  • To delete a read-only file, first you must remove the read-only attribute.
  • To delete or rename a file, you must have either delete permission on the file, or delete child permission in the parent directory.
  • To recursively delete the files in a directory, use the SHFileOperation function.
  • To remove an empty directory, use the RemoveDirectory function.
  • To close an open file, use the CloseHandle function.

Alıntı:Return value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero (0). To get extended error information, call GetLastError.


procedure TMainForm.ButtonResetClick(Sender: TObject);
var
 LSonuc : Cardinal;
begin
   FDConnection.Connected := False;
   LSonuc := Winapi.Windows.DeleteFile(pChar('C:\Users\Hulya\Documents\PList'));
   if LSonuc = 0 then ShowMessage('Error Message: '+ SysErrorMessage(GetLastError));
   MainForm := Nil;
   Application.Terminate; // Close
end;

Saygılarımla
Muharrem ARMAN

guplouajuixjzfm15eqb.gif
Cevapla
#3
USES
SHELLAPI;

function DelDir(dir: string): Boolean;
var
 fos: TSHFileOpStruct;
begin
 ZeroMemory(@fos, SizeOf(fos));
 with fos do
 begin
   wFunc  := FO_DELETE;
   fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
   pFrom  := PChar(dir + #0);
 end;
 Result := (0 = ShFileOperation(fos));
end;

// Kullanımı
procedure TForm1.Button1Click(Sender: TObject);
begin
DelDir('C:\DENEME')
end;
__________________________
From Now I will only Reading.
Cevapla
#4
(08-02-2023, Saat: 15:10)COMMANDX Adlı Kullanıcıdan Alıntı:
USES
SHELLAPI;

function DelDir(dir: string): Boolean;
var
 fos: TSHFileOpStruct;
begin
 ZeroMemory(@fos, SizeOf(fos));
 with fos do
 begin
   wFunc  := FO_DELETE;
   fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
   pFrom  := PChar(dir + #0);
 end;
 Result := (0 = ShFileOperation(fos));
end;

// Kullanımı
procedure TForm1.Button1Click(Sender: TObject);
begin
DelDir('C:\DENEME')
end;

Teşekkür ederim klasör silindi.

(08-02-2023, Saat: 13:50)mrmarman Adlı Kullanıcıdan Alıntı: Dönen hata kodunu değerlendirmeli ve ona göre çözüm aramalısınız.

ref : MSDN 

Silebilmeniz için gereken şartlar ;
Alıntı:The following list identifies some tips for deleting, removing, or closing files:
  • To delete a read-only file, first you must remove the read-only attribute.
  • To delete or rename a file, you must have either delete permission on the file, or delete child permission in the parent directory.
  • To recursively delete the files in a directory, use the SHFileOperation function.
  • To remove an empty directory, use the RemoveDirectory function.
  • To close an open file, use the CloseHandle function.

Alıntı:Return value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero (0). To get extended error information, call GetLastError.


procedure TMainForm.ButtonResetClick(Sender: TObject);
var
 LSonuc : Cardinal;
begin
   FDConnection.Connected := False;
   LSonuc := Winapi.Windows.DeleteFile(pChar('C:\Users\Hulya\Documents\PList'));
   if LSonuc = 0 then ShowMessage('Error Message: '+ SysErrorMessage(GetLastError));
   MainForm := Nil;
   Application.Terminate; // Close
end;




Hocam hata almıyordum, sizin paylaştığınız kodlarla yapmak istediğimde ise

[dcc64 Error] Main.pas(1379): E2010 Incompatible types: 'Cardinal' and 'LongBool'
[dcc64 Error] Main.pas(1379): E2010 Incompatible types: 'Cardinal' and 'LongBool'
[dcc64 Fatal Error] F2063 Could not compile used unit 'Main.pas'

Hatası aldım.
Cevapla
#5
Cardinal yerine longbool yazın isterseniz.

Ayrıca hata almıyorum diyorsunuz ama referans verdiğim MSDN linki açıklamasını okursanız göreceksiniz ki işlem yapılamadıysa sebebi vardır. Sebep ise anladığınız manada hata değildir. Zamanla karşılaştıklarınızla kavrarsınız.
Saygılarımla
Muharrem ARMAN

guplouajuixjzfm15eqb.gif
Cevapla
#6
@mrmarman teşekkür ederim bilgilendirme için.
Cevapla
#7
Güncel kütüphane fonksiyonlarını da kullanabilirsiniz.
uses System.IOUtils;
..
..
..
TDirectory.Delete('C:\Users\Hulya\Documents\PList');
gibi...
Cevapla


Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  APK nın çalıştığı klasör m_ekici 1 679 30-07-2024, Saat: 17:12
Son Yorum: frmman
  Android de Rehberden kayıt silme barissagir 6 2.452 24-12-2022, Saat: 09:51
Son Yorum: barissagir
  Telefonda son kaydedilen fotoyu silme barissagir 2 1.091 23-11-2022, Saat: 23:34
Son Yorum: barissagir
  Mobilede Listviewden Seçilen Kayıtı düzeltme silme vs. ilhanim 5 2.810 18-12-2020, Saat: 13:25
Son Yorum: ilhanim
  Insert ve Silme yakalama ahmetb 4 4.326 18-04-2019, Saat: 16:29
Son Yorum: shooterman



Konuyu Okuyanlar: 1 Ziyaretçi