Thread: How do I rename files through C++?

  1. #1
    Registered User
    Join Date
    Jan 2002

    How do I rename files through C++?

    What I am really trying to do is rename a large group of files with #'s, e.g. 001.doc, 002.doc, etc.. please help, newbie.

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    there is no function that i know of, but you can do it with a system call - as for renaming it with a number - use a variable that you increment and then use that as the filename (use a pointer to it)

    if you have an uncertain number of ilfes to rename you can use a while loop
    Monday - what a way to spend a seventh of your life

  3. #3
    Registered User
    Join Date
    Dec 2001
    #include <stdio.h>
    int rename( const char *oldfname, const char *newfname );

    The function rename() changes the name of the file oldfname to newfname. The return value of rename() is zero upon success, non-zero on error.

    Hope that helps

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Open the file, read it into the new as if you were reading the lines into strings in your program, then delete the old one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 08:36 AM
  2. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM