Reading the absolute file-path as sorted

I wanted to read out the absolute file-path (filename) as sorted in a folder (on Linux). The reading the file-paths is ok but I have problems in sorting.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

	selectedDirectory = fl_dir_chooser ("Select Imagedirectory:",NULL,0); //This is just a widget to show the folder.		
	DIR *d;
	dirent *de;
//  	char pfad[256];
	numberOfFilesOnSelectedFolder= 0;
	
	d=opendir(selectedDirectory); // Here you can enter the folder path instead selectedDirectory	
	while((de=readdir(d))){
	numberOfFilesOnSelectedFolder++;
	}
	closedir(d);
	
	
	d= opendir(selectedDirectory);
	
	std::vector <std::string> result;
	
	char buffer[500];
	int n;
	
	if (d) {
	while (true) {
	de= readdir(d);
	
	if (de == NULL) break;
	n= sprintf (buffer, "%s/%s", selectedDirectory, de->d_name);
	result.push_back( std::string(buffer));
      }
	closedir(d);
	std::sort( result.begin(), result.end() );
    }

cout << "result 3:" << result.at(0) << endl << result.at(1) << endl << result.at(2) << endl << result.at(3) << endl << result.at(4) << endl << result.at(5) << endl << result.at(6) << endl;
	



If I run this code and want determine what the 0th, 1st, 2nd, 3rd etc. files in the folder are, then I get the following answer:


result 3:/home/csad6517/Desktop/ViSeCut/Neck2/.
/home/csad6517/Desktop/ViSeCut/Neck2/..
/home/csad6517/Desktop/ViSeCut/Neck2/Unbenannt-105.dcm
/home/csad6517/Desktop/ViSeCut/Neck2/Unbenannt-106.dcm
/home/csad6517/Desktop/ViSeCut/Neck2/Unbenannt-107.dcm
/home/csad6517/Desktop/ViSeCut/Neck2/Unbenannt-36.dcm
/home/csad6517/Desktop/ViSeCut/Neck2/Unbenannt-37.dcm



The files -105.dcm, -106.dcm, -107.dcm lie in the folder at the bottom and -36.dcm, -37.dcm- at the top. The program compares 1 and 3 of 105 and 37, 1 is lesser than 3, then prints out first, but does not know that 105 is three digits and 37 is two digits. How can I solve this problem?

My directory looks:
http://www.wopsys.com/bilder/dateien.jpg



Thank you.

Do all your file names follow the same format?

ie. word-number.dcm?
No, not always. It comes first always a string, this is fixed. Then you can get a date and the character "-" then number.dcm

Some other file e.g.

../Hnovbh_Phantom-01.01.1900-CT-19.10.2007-17_21_00-0.dcm
../Hnovbh_Phantom-01.01.1900-CT-19.10.2007-17_21_00-1.dcm
../Hnovbh_Phantom-01.01.1900-CT-19.10.2007-17_21_00-2.dcm
...

../Hnovbh_Phantom-01.01.1900-CT-19.10.2007-17_21_00-100.dcm
../Hnovbh_Phantom-01.01.1900-CT-19.10.2007-17_21_00-101.dcm
...
Topic archived. No new replies allowed.