]> Creatis software - gdcm.git/blobdiff - Example/SplitIntoDirectories.cxx
Fix strange names
[gdcm.git] / Example / SplitIntoDirectories.cxx
index dc7b5db61979c2a6e7a2556c3fb544960f01f0b2..31c4aab46bbde700adbeb318658780f52879a948 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: SplitIntoDirectories.cxx,v $
   Language:  C++
-  Date:      $Date: 2011/04/20 14:06:50 $
-  Version:   $Revision: 1.7 $
+  Date:      $Date: 2011/04/22 14:39:41 $
+  Version:   $Revision: 1.10 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -266,7 +266,6 @@ int main(int argc, char *argv[])
    // or the field may be empty!   
    s->AddSeriesDetail(0x0020, 0x000d, false); // Study Instance UID (false : no convert)
 
-
    // You may prefer 0020 0011 Series Number
    // use :
    // s->AddSeriesDetail(0x0020, 0x0011, true);    
@@ -275,7 +274,6 @@ int main(int argc, char *argv[])
    s->AddSeriesDetail(0x0008, 0x103e, false); // Serie Description
    s->AddSeriesDetail(0x0020, 0x0011, false); // Serie Number (more than 1 serie may have the same Ser.Nbr don't 'convert!)
 
-   
    // Feel free to add more fields, if they can help a suitable (for you)
    // image sorting
 
@@ -354,8 +352,9 @@ int main(int argc, char *argv[])
       ///this is a trick to build up a lexicographical compliant name :
       ///     eg : fich001.ima vs fich100.ima as opposed to fich1.ima vs fich100.ima
       std::string name = GDCM_NAME_SPACE::Util::GetName( *it );
-      if (verbose)
-         std::cout << "name :[" << name << "]\n";
+
+     // if (verbose)
+     //    std::cout << "name :[" << name << "]\n";
 
       if (hasSkel)
       {
@@ -386,7 +385,6 @@ int main(int argc, char *argv[])
                            tokens[IND_SerieDescription] + token +
                            tokens[IND_SerieNumber]      + token +
                            tokens[IND_FileName];
-
       if (verbose) 
          std::cout << "[" << userFileIdentifier  << "] : " << *it << std::endl;
 
@@ -419,7 +417,7 @@ int main(int argc, char *argv[])
    previousSerieInstanceUID       = "";   
        
    GDCM_NAME_SPACE::File *currentFile;
-     
+   std::string replaceChar("_"); 
    for (it2 = sf.begin() ; it2 != sf.end(); ++it2)
    {  
       currentFile = it2->second;
@@ -445,7 +443,7 @@ int main(int argc, char *argv[])
          previousPatientName = currentPatientName;
          if (verbose)   
             std::cout << "==== new Patient  [" << currentPatientName  << "]" << std::endl;
-    
+
          previousPatientName            = currentPatientName;
          previousStudyInstanceUID       = ""; 
          previousSerieInstanceUID       = "";
@@ -469,14 +467,16 @@ int main(int argc, char *argv[])
          currentStudyWriteDir  = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                              + currentStudyInstanceUID;
          systemCommand   = "mkdir \"" + currentStudyWriteDir + "\"";
-         
+         if (verbose)
+            std::cout << "Directory [" << currentStudyWriteDir << "] created" << std::endl;
          if (listonly)
-           std::cout << "[" << systemCommand << "]" << std::endl;         
+            std::cout << "[" << systemCommand << "]" << std::endl;         
          else            
             system (systemCommand.c_str());
-
       }  
-      
+
       if (previousSerieInstanceUID != currentSerieInstanceUID)
       {        
          previousSerieInstanceUID       = currentSerieInstanceUID;
@@ -493,13 +493,16 @@ int main(int argc, char *argv[])
          else
             currentSerieWriteDir  = currentStudyWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                                   + currentSerieInstanceUID;         
-                      
+   
          systemCommand   = "mkdir \"" + currentSerieWriteDir + "\"";
          
          if (listonly)
             std::cout << "[" << systemCommand << "]" << std::endl;         
          else             
             system (systemCommand.c_str());
+
+         if (verbose)
+            std::cout << "Directory [" << currentSerieWriteDir << "] created" << std::endl;
       }            
    
       if ( GDCM_NAME_SPACE::Debug::GetDebugFlag())
@@ -508,11 +511,13 @@ int main(int argc, char *argv[])
                    << GDCM_NAME_SPACE::Util::GetName( fullFilename ) << std::endl;
  
       // If you want to create file names of your own, here is the place!
-      // Just replace 'lastFilename' by anything that's better for you.               
+      // Just replace 'lastFilename' by anything that's better for you.
+      GDCM_NAME_SPACE:: Util::ReplaceSpecChar(lastFilename, replaceChar);
+                   
       fullWriteFilename = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR 
                                          + lastFilename; 
 
-      systemCommand   = "cp \"" + fullFilename + "\"" + " \"" + fullWriteFilename + " \"";
+      systemCommand   = "cp \"" + fullFilename + "\"  \"" + fullWriteFilename + "\"";
       
       if (listonly)
          std::cout << "[" << systemCommand << "]" << std::endl;         
@@ -522,4 +527,3 @@ int main(int argc, char *argv[])
    }
    return 0;
  }
-