Skip to content

Instantly share code, notes, and snippets.

@MrSapps
Forked from zach-brockway/check_inc.py
Created June 3, 2016 09:46
Show Gist options
  • Save MrSapps/4992d2d460f4ef44538d62c9e875ca78 to your computer and use it in GitHub Desktop.
Save MrSapps/4992d2d460f4ef44538d62c9e875ca78 to your computer and use it in GitHub Desktop.
A quick-and-dirty python script to find invalid ClInclude nodes in VS 2010 projects
from __future__ import print_function
import os, stat
import sys
from collections import namedtuple
from shutil import move
import fileinput
import os
import os.path
import xml.etree.ElementTree as ET
def check_project(projectFileName):
ns = '{http://schemas.microsoft.com/developer/msbuild/2003}'
filterTree = ET.parse(projectFileName+".filters")
filterRoot = filterTree.getroot()
filterDict = dict()
missingDict = dict()
for inc in filterRoot.iter(ns+'ClInclude'):
incFileRel = inc.get('Include')
incFilter = inc.find(ns+'Filter')
if incFileRel != None and incFilter != None:
filterDict[incFileRel] = incFilter.text
if incFilter.text not in missingDict:
missingDict[incFilter.text] = []
projTree = ET.parse(projectFileName)
projRoot = projTree.getroot()
for inc in projRoot.iter(ns+'ClInclude'):
incFileRel = inc.get('Include')
if incFileRel != None:
incFile = os.path.abspath(os.path.join(os.path.dirname(projectFileName), incFileRel))
if not os.path.exists(incFile):
missingDict[filterDict[incFileRel]].append(incFileRel)
for (missingGroup, missingList) in missingDict.items():
if len(missingList) > 0:
print("["+missingGroup+"]:")
for missing in missingList:
print(" " + os.path.basename(missing) + " (" + missing + ")")
def find_missing_files():
for root, subdirs, files in os.walk(walk_dir):
for file in files:
name = os.path.join(root,file)
if name.endswith("vcxproj"):
if os.path.isfile(name + ".filters"):
print ("Processing file: " + name)
check_project(name)
walk_dir = 'C:\AnyDirThatHasVcxprojs'
find_missing_files()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment