static public Method

File.rename(p1, p2)

File.rename(old_name, new_name)    0

Renames the given file to the new name. Raises a SystemCallError if the file cannot be renamed.

File.rename("afile", "afile.bak")   #=> 0

Source Code

/*
*  call-seq:
*     File.rename(old_name, new_name)   => 0
*  
*  Renames the given file to the new name. Raises a
*  <code>SystemCallError</code> if the file cannot be renamed.
*     
*     File.rename("afile", "afile.bak")   #=> 0
*/

static VALUE
rb_file_s_rename(klass, from, to)
   VALUE klass, from, to;
{
   const char *src, *dst;
   SafeStringValue(from);
   SafeStringValue(to);

   src = StringValueCStr(from);
   dst = StringValueCStr(to);
#if defined __CYGWIN__
   errno = 0;
#endif
   if (rename(src, dst) < 0) {
#if defined DOSISH && !defined _WIN32
       switch (errno) {
         case EEXIST:
#if defined (__EMX__)
         case EACCES:
#endif
           if (chmod(dst, 0666) == 0 &&
               unlink(dst) == 0 &&
               rename(src, dst) == 0)
               return INT2FIX(0);
       }
#endif
       sys_fail2(from, to);
   }

   return INT2FIX(0);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.