# Method to delete a file using c++

**URL:** <https://forums.unrealengine.com/t/method-to-delete-a-file-using-c/143679>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [May 15, 2020, 2:40pm UTC](https://forums.unrealengine.com/t/method-to-delete-a-file-using-c/143679 "2020-05-15T14:40:29Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![samtkeen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@samtkeen](https://forums.unrealengine.com/u/samtkeen)\
**Post date:** [May 15, 2020, 11:58pm UTC](https://forums.unrealengine.com/t/method-to-delete-a-file-using-c/143679/3 "2020-05-15T23:58:46Z")

</div>

Thank you it works great but will crash if you have an invalid filename as your comment states.  
so a small addition to prevent any crash would be :

```auto

//Make sure the path I have is valid both in characters and in that the file path actually exists
if(!MyFile.isEmpty())
{
    if (FPaths::ValidatePath(MyFile) && FPaths::FileExists(MyFile))
    {
        IFileManager& FileManager = IFileManager::Get(); FileManager.Delete(*MyFile);
    }
}

```

Once again thank you!

---

_[View the full topic](https://forums.unrealengine.com/t/method-to-delete-a-file-using-c/143679)._
