Created
June 8, 2011 20:40
-
-
Save mikeobrien/1015350 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.IO | |
open System.Text.RegularExpressions | |
open System.Linq | |
let RegExGroups pattern (group1:string) (group2:string) source = | |
Regex.Matches(source, pattern, RegexOptions.IgnoreCase).Cast<Match>() | |
|> Seq.map (fun x -> (x.Groups.Item(group1).Value, x.Groups.Item(group2).Value)) | |
let IncludeRegEx = "<!--\\s*#include\\s+(?<type>\w*)\\s*=\\s*\"(?<url>.*)\"\\s*-->" | |
let GetIncludes virtualPath path = | |
File.ReadAllText(path) | |
|> RegExGroups IncludeRegEx "type" "url" | |
|> Seq.map (fun (x, y) -> if x = "virtual" | |
then Path.Combine(virtualPath, y) | |
else Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), y))) | |
|> Seq.map (fun x -> x.Replace("/", "\\").ToLower()) | |
let rec EnumerateIncludes virtualPath path = | |
let includes = GetIncludes virtualPath path | |
includes | |
|> Seq.filter (fun x -> File.Exists(x)) | |
|> Seq.collect (fun x -> EnumerateIncludes virtualPath x) | |
|> Seq.append includes | |
let FindNestedIncludes vitrualPath = | |
Directory.EnumerateFiles(vitrualPath, "*.asp", SearchOption.AllDirectories) | |
|> Seq.filter (fun x -> Path.GetExtension(x).Equals(".asp", StringComparison.OrdinalIgnoreCase)) | |
|> Seq.map (fun x -> (x.Replace(vitrualPath, String.Empty), | |
EnumerateIncludes vitrualPath x | |
|> Seq.groupBy (fun x -> x) | |
|> Seq.filter (fun (x, y) -> y.Count() > 1) | |
|> Seq.map (fun (x, y) -> x.Replace(vitrualPath.ToLower(), String.Empty)))) | |
|> Seq.filter (fun (x, y) -> y.Count() > 1) | |
FindNestedIncludes @"D:\webs\myapp" | |
|> Seq.iter (fun (x, y) -> printfn "%s\r\n%s" x (y |> Seq.fold (fun a x -> a + "\t" + x + "\r\n") String.Empty)) | |
printfn "Press a key sucka!" |> ignore | |
Console.ReadKey() |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment