In the next step we add the functionality for adding the project files from the specified main folder.
Implement a new helper function that is used to:
- Add files from the specified documents folder to the project.
- Scan the files to ascertain whether they are translatable (e.g. *.doc, *.ppt) or whether they cannot be processed by the application (e.g. pixel graphics) and are therefore set as reference, which means that they are not processed any further.
- A FileBasedProject object.
- The documents folder name (string).
- The recursion parameter to indicate whether sub-folders should be taken into account (boolean).
private void AddFiles(FileBasedProject project, string folder, bool recursion)
project.AddFolderWithFiles(folder, recursion);
- The ids of the files, which we previously retrieved
- The type of task that should be run on the project, i.e. Scan.
The complete function for adding and scanning the source files should look as shown below:
/// <summary>
/// Adds the files from the specified folder to the project and sets the file use, e.g. translatable or reference.
/// </summary>
#region "AddFilesFunction"
private void AddFiles(FileBasedProject project, string folder, bool recursion)
#endregion
{
#region "AddFolderWithFiles"
project.AddFolderWithFiles(folder, recursion);
#endregion
#region "GetSourceLanguageFiles"
ProjectFile[] projectFiles = project.GetSourceLanguageFiles();
AutomaticTask scan = project.RunAutomaticTask(
projectFiles.GetIds(),
AutomaticTaskTemplateIds.Scan);
#endregion
}