Efficiently Sorting File Paths
First, don't use the conditional operator as an if statement.  Either encode the conditional as part of the initialization of minSize, or use an if statement instead of the conditional.  In this case, though, a better solution is to make use of the standard min function:

int minSize = std::min(path1Expnded.size(), path2Expnded.size());


But we can redo your code to eliminate this part.

The sort you've coded and the one you describe (how I am interpreting your description, anyway) are different, as your code only looks at the number of subfolders if one path is in a subfolder of the folder that has the file in the other path.

Your problem description ("files closer to the root directory sorted first"), sounds like all the paths with fewer folders should be before longer ones, in which case the number of stems should be the first thing compared.  Then a direct comparison on the full paths if they have the same folder count.

What you've coded up will put files in a folder before subfolders of that folder.  Your current implementation does a lot of memory allocations and frees, mainly with strings and vector resizes.  You can simplify this a lot by first comparing the two parent_paths.  If they are different, return the result of this comparison (the path to a file will be shorter than the path for a subfolder in the folder with the file, so it'll be earlier).  Otherwise the two paths are the same, and return the result of comparing the filenames.