]> Creatis software - gdcm.git/blobdiff - Example/SplitIntoDirectories.cxx
Fix strange names
[gdcm.git] / Example / SplitIntoDirectories.cxx
index abcfbe75c18877f16da89cde16d99ce83750d474..31c4aab46bbde700adbeb318658780f52879a948 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: SplitIntoDirectories.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/05/28 15:44:34 $
-  Version:   $Revision: 1.5 $
+  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
@@ -185,7 +185,7 @@ int main(int argc, char *argv[])
    if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) )    // dirout not found
    {
       std::string strDirNameout(dirNameout);          // to please gcc 4
-      systemCommand = "mkdir " +strDirNameout;        // create it!
+      systemCommand = "mkdir \"" +strDirNameout + "\"";        // create it!
       if (verbose)
          std::cout << systemCommand << std::endl;
       system (systemCommand.c_str());
@@ -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
 
@@ -355,7 +353,8 @@ int main(int argc, char *argv[])
       ///     eg : fich001.ima vs fich100.ima as opposed to fich1.ima vs fich100.ima
       std::string name = GDCM_NAME_SPACE::Util::GetName( *it );
 
-      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;
@@ -435,24 +433,24 @@ int main(int argc, char *argv[])
       GDCM_NAME_SPACE::Util::Tokenize (it2->first, tokens, token);
       
       currentPatientName            = tokens[IND_PatientName];
-      currentStudyInstanceUID       = tokens[IND_StudyInstanceUID];      
+      currentStudyInstanceUID       = tokens[IND_StudyInstanceUID];     
       currentSerieInstanceUID       = tokens[IND_SerieInstanceUID];
       currentSerieDescription       = tokens[IND_SerieDescription];
       currentSerieNumber            = tokens[IND_SerieNumber];
-             
+
       if (previousPatientName != currentPatientName)
       {  
          previousPatientName = currentPatientName;
          if (verbose)   
             std::cout << "==== new Patient  [" << currentPatientName  << "]" << std::endl;
-    
+
          previousPatientName            = currentPatientName;
          previousStudyInstanceUID       = ""; 
          previousSerieInstanceUID       = "";
 
          currentPatientWriteDir = writeDir + currentPatientName;
 
-         systemCommand   = "mkdir " + currentPatientWriteDir;
+         systemCommand   = "mkdir \"" + currentPatientWriteDir + "\"";
          if (verbose || listonly)
             std::cout << "[" << systemCommand << "]" << std::endl;
          if (!listonly)
@@ -468,15 +466,17 @@ int main(int argc, char *argv[])
 
          currentStudyWriteDir  = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                              + currentStudyInstanceUID;
-         systemCommand   = "mkdir " + currentStudyWriteDir;
-         
+         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;
@@ -487,17 +487,22 @@ int main(int argc, char *argv[])
          if (seriedescr) // more human readable!
             currentSerieWriteDir  = currentStudyWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                                   + currentSerieDescription + "_" + currentSerieNumber
-                                  + "_" + currentSerieInstanceUID;
+                                  /*+ "_" + currentSerieInstanceUID */
+                                  ;
+
          else
             currentSerieWriteDir  = currentStudyWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                                   + currentSerieInstanceUID;         
-                      
-         systemCommand   = "mkdir " + currentSerieWriteDir;
+   
+         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())
@@ -506,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;         
@@ -520,4 +527,3 @@ int main(int argc, char *argv[])
    }
    return 0;
  }
-