Jump to content
Sign in to follow this  
cypher175

How Do I Rename a File..?

Recommended Posts

cypher175

What is the function to rename a file..??

Share this post


Link to post
Share on other sites
Andreik

Another way(not so good like FileMove):

RunWait(@ComSpec & " /C ren " & $file & " " & $newname, "", @SW_HIDE)
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites
cypher175

As there is no real "FileRename" you have to Use

FileMove("oldname.txt", "newname.txt")
what if the file I want rename is the actual Script.exe and its already running

how can I rename the script.exe while its still running..??

Share this post


Link to post
Share on other sites
senthor

Not that easy but possible too:

If $CMDLine[0] > 1 and CMDLine[1] = "copy" and FileExists($CMDLine[2]) and @compiled = 1 Then
    Sleep(100)
    If $CMDLine[2] <> @autoitexe then FileDelete($CMDLine[2])
EndIf

FileMove(@scriptfullpath, $newdir)
Run('"' & $newdir & '" copy ' & @scriptfullpath)
Exit

senthor

Edited by senthor

Share this post


Link to post
Share on other sites
cypher175

that seems like an awful lot of code just to simply rename a file..

Out of all the functions why is ''FileRename" not in there..

Why did they leave it out for..??

Its like a basic function..??

Share this post


Link to post
Share on other sites
senthor

Of course it is, but try to rename a exe file while it's running - won't work.

Same problem here.

So you have to copy the script, run the new one and delete the old after quitting it.

Share this post


Link to post
Share on other sites
cypher175

if you use a batch script to .exe app you can rename your script.exe while its running with this simple line:

REN %~0 TEST.EXE

and it works fine..

But with AutoIt you have to copy the script to a diff name, run the new script.exe which will delete the old script.exe..

Share this post


Link to post
Share on other sites
cypher175

wait a sec, I just tried this code and it worked just fine..

FileMove(@ScriptName, "NewName.exe")

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.