954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

[STRINGS] Delete all chars before mark

Hi there.

I'm writing a simple system to order certain data.
Now this is the deal: I have a bunch of files with the following filename structures (stored as strings):
0000[i]_FILENAME.EXT

i represents a random number. Now I want to scan whether the file has that structure, and if it has that structure, it should rename it to FILENAME.EXT.

So basically, I want to program to check whether a certain structure is present in the filename, and if so, it should rename the string.

Any ideas how on how to solve this problem?

Thanks in advance!


Eddy Wally

EddyWally
Newbie Poster
2 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Something like this?

char filename[] = "00001234_FILENAME.EXT";
char newfilename[100];
if ( sscanf( filename, "0000%*d_%s", newfilename) == 1 ) {
  // format seems to be as expected
  rename(filename,newfilename);
}
Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

That's amazing! Thank you very much!

EddyWally
Newbie Poster
2 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: