How do I rename files through C++?

This is a discussion on How do I rename files through C++? within the C++ Programming forums, part of the General Programming Boards category; What I am really trying to do is rename a large group of files with #'s, e.g. 001.doc, 002.doc, etc.. ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    1

    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
    Posts
    1,385
    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
    Posts
    194
    rename
    Syntax:
    #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.

    http://www.cppreference.com/

    Hope that helps

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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, 10:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21