Jump to content
Sign in to follow this  

filerename function

Recommended Posts



;File Rename


;0 For successful

;1 For Did not enter File to be Renamed

;2 For Did not enter new file name

;3 For File Does not Exist

; _filerename($oldfilename, $newfilename)

;$oldfilename - enter the file you with to be rename including the full path

;$newfilename - enter the name you want it, but not the path

;Example - _filerename("c:\helpme.txt", "Idonotneedhelp.txt")

;Result c:\Idonotneedhelp.txt

;By Flip209


Func _filerename($oldfilename, $newfilename)

$i = 0

Dim $string

If $oldfilename = "" Then

Return 1

ElseIf $newfilename = "" Then

Return 2

ElseIf not FileExists($oldfilename) Then

Return 3


$split = StringSplit($oldfilename, "\")


If $i <> 0 Then $string &= $split[$i] & "\"

$i += 1

Until $i = $split[0]

$string &= $newfilename

FileMove($oldfilename, $string)

If FileExists($string) then Return 0

EndFunc ;==>_filerename



0 if good

1 no source file

2 no name to rename to

3 file does not exist

Edited by flip209

" I haven't failed. I've just found 10,000 ways that won't work." Thomas Edison "You cannot help men permanently by doing for them what they could and should do for themselves." Abraham Lincoln

Share this post

Link to post
Share on other sites

LMAO I dropped the p it what suppose to be bump....LMAO My bad

Understood as much, guess I was trying to tell you its annoying to Bump something this quickly that doesn't even contain anything that needs answering.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites


Returning 0 on success isn't such a good idea.


If _FileRename("Blah.txt", "Hi.txt") Then
     MsgBox(0, "Error", "There was an error")

See FileMove Return Values in the helpfile to see what it should return :D

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  

  • Create New...