commands.cc
/*
** rename_file - rename src to dest and update window appropriately.
*/
rename src to dest and update window appropriately.
rename src to dest and update window appropriately .
static void rename_file(DirList *dl, const char *src, const char *dest)
{
    if (rename(src, dest) != -1)
    {
        message("`rename' was successful");
        if (in_same_directory(dl, dest))
        {
             The important point to note about the following code
             is that if `dest\' is a directory, we need to add a `d\'
             to the ls command as in
               ls -ld source
            int is_dir = is_directory(dest);
            size_t size = strlen(ls_cmd[the_sort_order()]) + strlen(dest) + 3;
            if (is_dir) size++;
            String command = ls_cmd[the_sort_order()];
            if (is_dir) command += "-d";
            command += String(" ") + dest;
            FILE *fp = popen(command, "r");
            if (fp == 0)
                error("File %s, line %d: popen(%s) failed",
                      __FILE__, __LINE__, (const char *)command);
            char *new_line = fgetline(fp);
            if (new_line == 0)
                error("File %s, line %d: fgetline() failed",
                      __FILE__, __LINE__);
            (void)pclose(fp);
            update_current_line(dl, new_line);
        }
        else
            remove_listing_line(dl, dl->savedYPos());
    }
    else
    {
        message("`rename' failed");
        move_cursor(dl->savedYPos(), dl->savedXPos());
    }
}
static void rename_file ( DirList * dl , const char * src , const char * dest ) { if ( rename ( src , dest ) != -1 ) { message ( " " ) ; if ( in_same_directory ( dl , dest ) ) { int is_dir = is_directory ( dest ) ; size_t size = strlen ( ls_cmd [ the_sort_order ( ) ] ) + strlen ( dest ) + 3 ; if ( is_dir ) size ++ ; String command = ls_cmd [ the_sort_order ( ) ] ; if ( is_dir ) command += " " ; command += String ( " " ) + dest ; FILE * fp = popen ( command , " " ) ; if ( fp == 0 ) error ( " " , __FILE__ , __LINE__ , ( const char * ) command ) ; char * new_line = fgetline ( fp ) ; if ( new_line == 0 ) error ( " " , __FILE__ , __LINE__ ) ; ( void ) pclose ( fp ) ; update_current_line ( dl , new_line ) ; } else remove_listing_line ( dl , dl -> savedYPos ( ) ) ; } else { message ( " " ) ; move_cursor ( dl -> savedYPos ( ) , dl -> savedXPos ( ) ) ; } }
rename_file - rename src to dest and update window appropriately.
rename_file - rename src to dest and update window appropriately .
// // The important point to note about the following code // is that if `dest\' is a directory, we need to add a `d\' // to the ls command as in // //   ls -ld source //