renaming file is driving me crazy!!

Hi
I am trying to write a very simple script to find a file in the same location(file1.txt) as the script application, and rename it(to file2.txt).
I have been trying for the last several hours and i can’t get it to work. Here is what i have so far:

This give me an error saying that the file i am trying to rename it to(file2.txt) cannot be found.
Can anyone tell me why on earth this isn’t working?

when i change the name of a file i use the unix mv command. So assuming you know the paths to the original file (origPath) and the new file (newPath) then…

First, coerce your file path to a string
set stringOrigPath to origPath as string
set stringNewPath to newPath as string

Then change your mac formatted file path to the unix path
set origUnixPath to quoted form of POSIX path of stringOrigPath
set newUnixPath to quoted form of POSIX path of stringNewPath

Last run the unix command
do shell script "mv " & origUnixPath & " " & newUnixPath

Change this line

set name of filepath1 to ((folder1 & "file2.txt") as alias)

to this

set name of file filepath1 to "file2.txt"

CJ is correct. The reason, which he didn’t give, is that when a script is compiled to run, the compiler tries to resolve all aliases. If an alias points to a file that has yet to be created, the resolution to its alias fails because the file cannot be found - it isn’t there yet, so the error message makes sense.

Thanks, Adam, for adding the explanation. It’s more thorough than the one I accidentally cut out.

j

Thanks guys.
Thats exactly what i though the problem was originally so i had changed it to this:

tell application "Finder"
	set sourcepath to (path to me)
	set folder1 to folder of sourcepath as string
	set filepath1 to folder1 & "file1.txt"
	set name of filepath1 to "file2.txt"
end tell

but it gives me an error saying "Can’t set name of “Macintosh HD:Users:apple:Desktop:test:file1.txt” to “file2.txt”
I am sure this is some sort of incompatible types problem, but I’m not sure what. It would be nice if the error messages were a bit more descriptive.
I will try the ‘mv’ command option, but i would really like to get this done in applescript so that it can be more easily maintained. Also, it should be so easy to do, and yet it is just not working for me.
Does my Mac have some sort of vendetta against me(maybe because i installed Bootcamp)?

OK, feeling a little silly here.
I was omitting the word ‘file’ from the script. I have put that in and it works!!
yay!

tell application "Finder"
   set sourcepath to (path to me)
   set folder1 to folder of sourcepath as string
   set filepath1 to folder1 & "file1.txt"
   set name of file filepath1 to "file2.txt"
end tell

Thanks everyone here for your help