Created
September 8, 2014 13:49
-
-
Save AlexArchive/dd3b8402866cf890b07b to your computer and use it in GitHub Desktop.
(F# versus. C#) Print all file paths in both top level directories and sub directories.
This file contains 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
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
namespace ConsoleApplication9 | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
using (var writer = new StreamWriter("C:\\Users\\ByteBlast\\Desktop\\dump.txt")) | |
{ | |
foreach (var file in AllFilesUnder("M:/othr")) | |
writer.WriteLine(file); | |
} | |
} | |
static IEnumerable<string> AllFilesUnder(string basePath) | |
{ | |
foreach (var file in Directory.GetFiles(basePath)) | |
yield return file; | |
foreach (var x in Directory.GetDirectories(basePath).Select(AllFilesUnder).SelectMany(files => files)) | |
yield return x; | |
} | |
} | |
} |
This file contains 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.IO; | |
let rec allFilesUnder basePath = | |
seq { | |
yield! Directory.GetFiles(basePath) | |
for subdir in Directory.GetDirectories(basePath) do | |
yield! allFilesUnder subdir | |
} | |
[<EntryPoint>] | |
let main args = | |
use writer = new StreamWriter("C:\\Users\\ByteBlast\\Desktop\\dump.txt") | |
(allFilesUnder "M:/othr") |> Seq.iter writer.WriteLine | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment