![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 1
Rep Power: 0
![]() |
What I want to be able to do is:
1. Acquire all of the names in a file 2. Store all the names in the file 3. Change the stored names to other names 4. Save the new names over the orignal names. Is there any easy way to store the original names and be able to alter then than save them? |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
Did you try searching google first?
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
Here is a file renaming function that is part of one of my file libraries.
Make sure you have the fstream header included, and the function declared. int RenameFile(char* old, char* newF) { int result; result= rename( old , newF ); if (result != 0 ) perror( "Error renaming file" ); return 0; } Look through the available features of fstream and you will see how to do the rest. If not msg back.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Expert Programmer
|
You know a map would be a really good container to use to accomplish that function. If you store the names of the file within a file and change the names there first, you are not going to know the original file names to change. You will need to maintain a file which keeps the file name maps.
Ultimately you could just use a map class in C++ and maintain the map of all files, store the full directory of the file (relative to your listing point) to prevent map collisions, and the map value will be the name you want to change the file to. Iterate through your map and make the changes you want, popping values off your map (or erasing them since I do not think you can pop from a map) as you rename each of your files. Store results into a file or on the stdout if you want. Using IR's rename code is probably the most robust means, if you do not need robust remember you can always use system( "mv orginal_filename new_filename" )--if you do that remember to use full diretories in your map key and value.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|