You just forgot the do's. By the way, the compiler recommends you use yield and yield! instead of -> and ->>. Also, all exceptions will hold when upcasting to System.Exception, so you don't have to bind it to 'e'.

1
2
3
4
5
6
7
let rec allFiles1 dir =
    try
        seq { for file in Directory.GetFiles(dir) do
                yield file
              for subdir in Directory.GetDirectories dir do
                yield! (allFiles1 subdir) }
    with _ -> Seq.empty

EDIT: Something was bothering me, so I retried the code you entered. I was able to get it to run with no modifications. So, I would assume that there is a problem with your spacing. Try copying/pasting the following code into your file and see if that works:

1
2
3
4
5
6
7
let rec allFiles1 dir =
  try
    seq { for file in Directory.GetFiles(dir) -> file
          for subdir in Directory.GetDirectories dir ->> (allFiles1 subdir) }
  with :? System.Exception as e -> Seq.empty

allFiles1 @"c:\WINDOWS\system32" |> Seq.iter (fun s -> printfn "%A" s)

Regards,

z.

By on 1/26/2008 12:45 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper