Renaming Folders ?

Hi,

I am trying to rename a folder for example

Test.Folder.1422

to

Test Folder 1422

but eventually I want to be able to rename ALL subfolders inside a directory with some parameters.

So for example if I had a folder called "All folders" and inside that I had:

Test.Folder.1422
Test.Folder.1423
Test.Folder.1424
Test.Folder.1425
Test.Folder.1426
Test.Folder.1427
Test.Folder.1428

and wanted to rename them by replacing all fullstops / periods with a blank space how would I do that?

Thanks.
closed account (Dy7SLyTq)
*nix or windows?
Ah sorry forgot to say , Windows. Vc++.
Last edited on
closed account (3qX21hU5)
Are you asking from a programming aspect or from just a standard computer use aspect?

Really we would need to see some of your code to help you out with this if it is from a programming aspect because it is hard to tell what you are actually doing.

But the short answer would be find each instance of a "." or "/" in the folder names and replace them with a " ". Which is pretty standard.

But again we will need to see your code.
From a programming aspect,

I have followed the examples and writing to / from text files etc , also managed to find correct file sizes of a specified folder but I have no idea where to start with renaming folders, so at the moment there is no code. I am a complete beginner but a very fast learner so any advice would be welcome.

But the short answer would be find each instance of a "." or "/" in the folder names and replace them with a " ". Which is pretty standard.


Yeah that is what I have asked for but I have no idea how to actually write it.
Using boost filesystem http://www.boost.org/doc/libs/1_53_0/libs/filesystem/doc/index.htm

(untested code):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>
#include <iostream>

void recursive_rename_subdirs( const std::string& dir_name )
{
    using namespace boost::filesystem ;

    try
    {
       if( exists(dir_name) && is_directory(dir_name) )
       {
           std::string new_name = dir_name ;
           for( char& c : new_name ) if( c == '.' ) c = ' ' ;
           if( new_name != dir_name ) rename( dir_name, new_name ) ;

           for( directory_iterator iter(new_name) ; iter != directory_iterator() ; ++iter )
                 recursive_rename_subdirs( iter->path().string() ) ;
       }
    }

    catch( const filesystem_error& error ) { std::cerr << error.what() << '\n' ; throw ; }
}
Last edited on
Topic archived. No new replies allowed.