← Docs
kotlin-stdlib / kotlin.io.path / java.nio.file.Path / deleteIfExists

deleteIfExists

JVM
JRE7
1.5
fun Path . deleteIfExists ( ) : Boolean
(source)

Deletes the file or empty directory specified by this path if it exists.

Exceptions

DirectoryNotEmptyException - if the directory exists but is not empty

Return true if the existing file was successfully deleted, false if the file does not exist.

See Also

Files.deleteIfExists

Stay in touch:
  • Contributing to Kotlin
  • Releases
  • Press Kit
  • Security
  • Blog
  • Issue Tracker
  • Brand assets
  • Careers
Supported and developed by JetBrains .
Kotlin™ is protected under the Kotlin Foundation
and licensed under the Apache 2 license .