# Alternative to io.rename() for editor scripts

**URL:** <https://forum.defold.com/t/alternative-to-io-rename-for-editor-scripts/75945>\
**Category:** The Defoldmine\
**Created:** [February 8, 2024, 8:44pm UTC](https://forum.defold.com/t/alternative-to-io-rename-for-editor-scripts/75945 "2024-02-08T20:44:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wistpotion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/wistpotion/32/29771_2.png) [@Wistpotion](https://forum.defold.com/u/Wistpotion)\
**Post date:** [February 8, 2024, 8:44pm UTC](https://forum.defold.com/t/alternative-to-io-rename-for-editor-scripts/75945/1 "2024-02-08T20:44:29Z")

</div>

To be able to rename files in editor scripts I wrote this horror of a function:

```lua
local function hacky_rename(old_path, new_path)
    local old_file = io.open(old_path, "rb")
    local old_data = old_file:read("*a")
    io.close(old_file)

    local new_file, err = io.open(new_path, "wb")
    new_file:write(old_data)
    io.close(new_file)
end

```

Example usage:

```lua
hacky_rename("./main/main.collection", "./main/not_main.collection")

```
