Filename concatenation eats folder parts



  • On 23/08/2016 at 13:26, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R17 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi everyone,

    I was integrating GenerateTexturePath to my assets and have noticed one confusing thing with filename concatenation when I wanted to concanate a project directory path and filename relative path (including subfolders) and the filename itself.

    	Filename doc_dir = doc>GetDocumentPath();
    	Filename suggested_dir = texFilename.GetDirectory();
    	Filename src_file = texFilename.GetFile();
    	Filename dst_name;
      
    	Filename dir2 = doc_dir + suggested_dir;
      
    	printf("\n doc_dir: %s",		doc_dir.GetString().GetCStringCopy());
    	printf("\n src_file: %s",		src_file.GetString().GetCStringCopy());
    	printf("\n suggested_dir: %s",	suggested_dir.GetString().GetCStringCopy());  
    	printf("\n dir2: %s",			dir2.GetString().GetCStringCopy());
    

    It prints for given filename ./folder1/folder2/12.jpg typed to FILENAME field

    doc_dir F:\Development	est scenes
    src_file 12.jpg
    suggested dir: ./folder1/folder2
    dir2: F:\Development	est scenes\folder2
    

    But why dir2 is F:\Development est scenes\folder2???

    It should be dir2: F:\Development est scenes\folder1\folder2 instead



  • On 25/08/2016 at 01:43, xxxxxxxx wrote:

    Hello,

    it appears that the "+" or "+=" operator of the Filename class only adds the last part of the given Filename which is typically the actual name of the file. As far as I can see you would have to deconstruct the second Filename and add every part manually. This is some rough implementation you can use as a starting point to build your own solution. Don't forget to test this on all supported platforms:

      
    Filename       fullPath  = Filename("F:\\Development\\test scenes");  
    const Filename extraPath = Filename("./folder1/folder2");  
      
    const String extraPathString = extraPath.GetString();  
      
    Int32 start = 0;  
    Int32 found = 0;  
      
    // loop through filename parts  
    while (extraPathString.FindFirst("/", &found, start))  
    {  
      String subStr = extraPathString.SubStr(start, found - start);  
      if (subStr != ".")  
      fullPath += subStr;  
      
      start = found + 1;  
    }  
      
    // add rest  
    const Int32  length = extraPathString.GetLength();  
    const String subStr = extraPathString.SubStr(start, length - start);  
    fullPath += subStr;  
      
    GePrint("result: " + fullPath.GetString());  
    

    best wishes,
    Sebastian


Log in to reply