3

How do I delete a file or folder on the internal storage in android with Delphi for android

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Mysapta
  • 53
  • 1
  • 5

2 Answers2

7

You should use the TFile and TDirectory classes in the System.IOUtils unit.

For example:

TDirectory.Delete(<YOUR DIR PATH>);

or

TFile.Delete(<YOUR FILE PATH>);

Look in Embarcadero's documentation to get the right path of your files and folders on the various platforms:

Standard RTL Path Functions across the Supported Target Platforms

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
taked0wn
  • 86
  • 1
  • 1
1

Referred from :

https://stackoverflow.com/a/27047502/5193608 https://stackoverflow.com/a/3554949/5193608

Main Part from both links:

You should always delete files that you no longer need. The most straightforward way to delete a file is to have the opened file reference call delete() on itself.

myFile.delete();

If the file is saved on internal storage, you can also ask the Context to locate and delete a file by calling deleteFile():

myContext.deleteFile(fileName);

Note: When the user uninstalls your app, the Android system deletes the following: All files you saved on internal storage All files you saved on external storage using getExternalFilesDir(). However, you should manually delete all cached files created with getCacheDir() on a regular basis and also regularly delete other files you no longer need.

Source : http://developer.android.com/training/basics/data-storage/files.html

Directly you can do is :

File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();

Hope,it helps!

Community
  • 1
  • 1
Animesh Mangla
  • 773
  • 7
  • 31