Lua Rename Function


Main Question:
Can I have my Lua script rename a file in my garrysmod directory?

This is for spawned models, not the playermodel
This is for models without multiple skins already available using the ‘c’ option

rename() function gives me the error: “attempt to call global ‘rename’ (a nil value)”

**Trying: **

oldname = "C:\\path\\path\\path\\filename.vtf"
newname = "C:\\path\\path\\path\\filename_new.vtf"
rename (oldname, newname)

I have never coded in Lua. This is just a simple tool for my own use.

Thanks for the help even it if just means I should stop what I am attempting.

The rename function is for presets; you can’t rename a file in GMod via lua.

OK, so that saves me time looking into it any further. It was not very necessary anyway, just for fun, and slightly easier to accomplish the task.

Thank you for the quick reply

[del]You could read a file, write a new file with the contents and delete the old one. It would be the same thing.[/del]
Forget it, I forgot you can only write .txt without a module.

He’s doing it for a .vtf, though, not a .lua or .txt file. The best way would just be to download a new copy with a different name.

Yeah, thanks again.

It is really not difficult to pop out and swap a .vtf really quickly. I just thought it would be extra easy if I could do it in game. I also thought it would be an easy first tool to create.

Oh well, I learned stuff along the way and now have a somewhat useless tool that displays the model name. Maybe I will modify it to simply add the full path to the clipboard with a click. I know you can get that by right clicking on the model in the menu but it could be useful when we have 100 props out and don’t want to go find it in the menu again.

Turning a dead end into a new vaguely useful opportunity, heh.

I think someone made a module a while ago that allowed you to write whatever extension you want, if you put it on the server (or client if you need it client sided) you can still do it. It just takes a bit more work.
EDIT: I’ve been searching a while and can’t find it.

That sounds interesting. I would be interested in playing with that if we can find it.

I also just found a tool that does what I said about copying paths.

Maybe I can tweak it if it does not meet my specific needs and learn more along the way.


Yeah that is how I usually do it. (use the spawnmenu)

But sometimes we build build huge sets and after hours of placing objects it is easier to simply click on the prop you are looking at instead of opening the menu and searching around for it each time.

Every shortcut adds up on big projects! :slight_smile:

Now to look into creating directories hehe