# Request: File::reName()

**URL:** <https://forum.juce.com/t/request-file-rename/20483>\
**Category:** General JUCE discussion\
**Created:** [January 4, 2017, 10:23am UTC](https://forum.juce.com/t/request-file-rename/20483 "2017-01-04T10:23:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![loopfine](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/loopfine/32/141_2.png) [@loopfine](https://forum.juce.com/u/loopfine)\
**Post date:** [January 4, 2017, 10:23am UTC](https://forum.juce.com/t/request-file-rename/20483/1 "2017-01-04T10:23:55Z")

</div>

```
bool rename (const String& newName)

```

`File::moveFileTo()` also can rename a file/dir, but it’s a little bit inconvenient…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 4, 2017, 10:35am UTC](https://forum.juce.com/t/request-file-rename/20483/2 "2017-01-04T10:35:05Z")

</div>

But this would be exactly the same as moveFileTo… What’s so inconvenient?

---

<div class="post-metadata">

**Author:** ![loopfine](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/loopfine/32/141_2.png) [@loopfine](https://forum.juce.com/u/loopfine)\
**Post date:** [January 4, 2017, 12:05pm UTC](https://forum.juce.com/t/request-file-rename/20483/3 "2017-01-04T12:05:51Z")

</div>

1. **Semantic ambiguity**. `moveFileTo()` more likes the ‘cut, paste, then rename’ operates in nature.
2. **Different object(s)**. `moveFileTo()` involves 2 file objects while `rename()` is one. What we need just a new name (a string).
3. **Certainty and uncertainty**. Especially when spanned volume operate of `moveFileto()` happened on Windows (refer to the comments of this method). `rename()` will nothing about that.
4. For the **integrality** of the File class.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 4, 2017, 5:44pm UTC](https://forum.juce.com/t/request-file-rename/20483/4 "2017-01-04T17:44:36Z")

</div>

I don’t agree that this would be a good addition - I think two methods that do the same thing would be confusing. But remember you don’t always need us to update the library in order to get the function you need, e.g. this is a one-liner for you to write yourself:

```
bool renameFile (const File& f, const String& newName) { return f.moveFileTo (f.getSiblingFile (newName); }

```

---

<div class="post-metadata">

**Author:** ![gm1](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gm1](https://forum.juce.com/u/gm1)\
**Post date:** [August 25, 2022, 9:02am UTC](https://forum.juce.com/t/request-file-rename/20483/5 "2022-08-25T09:02:13Z")

</div>

Added a missing closing bracket and “juce::” for other people who happen to come accross this thread and just want to use jules’ quick one-liner:  
`bool renameFile (const juce::File& f, const juce::String& newName) { return f.moveFileTo (f.getSiblingFile (newName)); }`
