Author Topic: Adding dirs automatically?  (Read 3176 times)

Offline dkaip

  • Multiple posting newcomer
  • *
  • Posts: 42
Adding dirs automatically?
« on: November 30, 2018, 07:44:27 am »
Hi.
I am trying to impor many files recursively.
That's ok, but there are too many dirs and compiler says i don’t find the file until add the dir.
There is a way automatically add dirs when adding recursively files?
Thank's
Jim

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Adding dirs automatically?
« Reply #1 on: November 30, 2018, 09:37:14 am »
Are you talking about search dirs in the project -> build options?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dkaip

  • Multiple posting newcomer
  • *
  • Posts: 42
Re: Adding dirs automatically?
« Reply #2 on: November 30, 2018, 11:13:47 am »
Yes. I am trying to import many files recursively  from a big number of dirs.
The cpp and h files adding in project, but the dirs no.
Is that possible to adding dirs parallel or from a plug in that searches files an add dirs automatically or from build>Search directories?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Adding dirs automatically?
« Reply #3 on: November 30, 2018, 11:52:12 am »
I don't think you can do it from the UI.
Probably it could be done if you write a script.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dkaip

  • Multiple posting newcomer
  • *
  • Posts: 42
Re: Adding dirs automatically?
« Reply #4 on: November 30, 2018, 02:09:12 pm »
That is sure, but there is a problem.
If writing a script, this maybe will add all sub-dirs that will produce problem.
But if at recursive dialogue is a check box that tells to add every new dir that finds, maybe is better way.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Adding dirs automatically?
« Reply #5 on: December 01, 2018, 12:30:13 am »
I do not understand what you are saying in the last post, but i made a script that goes through the active project and adds all folders with include files in it to the include search directories under build options.

Feel free to test, but i give no guarantee that it will work. Make a copy of your project first...
Code

local CheckIfPathIsInProjectList = function (path)
{
    local includeArray = GetProjectManager().GetActiveProject().GetIncludeDirs();
    for(local i = 0; i < includeArray.GetCount(); ++i)
    {
        if(includeArray.Item(i).tostring() == path)
            return true;
    }
    return false;
}

print("#### Script begin #####");

local project = GetProjectManager().GetActiveProject();
print("Work on project: " + project.GetTitle());

local fileCount = project.GetFilesCount();
print("Number of files in project " + fileCount);

// Itearete trought the files
for(local i = 0; i < fileCount ;++i)
{
    local ProjectFile = project.GetFile(i);
    if(ProjectFile.file.GetExt().tostring() == "h")   // Check if file is a header file
    {
        local includePath = ProjectFile.relativeFilename.BeforeLast('/').tostring();
        if( CheckIfPathIsInProjectList(includePath) == false)
        {
            project.AddIncludeDir(_T(includePath));
            print("Add folder: " + includePath);
            project.SetModified(true);
        }
    }
}

print("#### Script end #####");
To run the script copy and paste the above in a new text file. rename it with the file ending
Code
.script
Open the project in question and open the script console with View->Scripting console
open the script from the console with clicking on the second button.
As soon as you open the script it will run. If you are working on windows you may have to adjust the path delimiter in line 27
If your header files have different fileextension as "h" you have to modify it in line 25.

hope this helps.

PS: i found a bug in squirrel or SQPlus, i am not sure:
you can not call the function
Code
GetIncludeDirs()
on a project variable passed through a function parameter.