Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 3rd, 2004, 1:57 PM   #1
Matronix
Newbie
 
Join Date: Sep 2004
Posts: 1
Rep Power: 0 Matronix is on a distinguished road
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?
Matronix is offline   Reply With Quote
Old Sep 3rd, 2004, 2:34 PM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Did you try searching google first?
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Sep 3rd, 2004, 4:03 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Sep 3rd, 2004, 5:49 PM   #4
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:51 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC