이제

2010-02-25 2 views
1

내가 파이프 라인에 하나의 value or tubles을 추가 할 수 있습니다, 나의 다음 질문은 내가 목록/배열을 추가 할 수있다 파이프 라인 |>, 아니면 내가 할 수 있습니까?이제

Assembly.GetExecutingAssembly.GetFiles() 
|>Array.map (fun file -> file.ReadAllText().Contains(keyword)) 
 

답변

2

귀하의 코멘트를보고 당신이 이것을하려고합니까?

Assembly.GetExecutingAssembly().GetFiles() 
|> Seq.map (fun file -> 
    let stream = new StreamReader(file) 
    file, stream.ReadToEnd().Contains(keyword)) 
|> Seq.filter snd 
|> Seq.map fst 
|> Seq.iter (fun file -> printfn "%s" file.Name) 

명령형 스타일은 더 깨끗할 수 있습니다.

for file in Assembly.GetExecutingAssembly().GetFiles() do 
    let stream = new StreamReader(file) 
    if stream.ReadToEnd().Contains(keyword) then 
     printfn "%s" file.Name 
3

I에 대한 질문이 무엇인지 이해하지만, 올바른 버전없는입니다

open System.Reflection 
open System.IO 

Assembly.GetExecutingAssembly().GetFiles() 
|> Seq.map (fun file -> new StreamReader(file)) 
|> Seq.map (fun file -> file.ReadToEnd().Contains(keyword)) 
|> Seq.iter(printfn "%s") 

먼저 당신이 GetExecutingAssembly이 필요하고 그 결과를해야합니다. 그래서 (). 두 번째 GetFiles()의 배열은 Stream이고 FileInfo이 아니라 예상대로 반환 할 수 있습니다. 이 때문에 StreamStreamWriter으로 감싸 야합니다.

그게 전부입니다.

+0

예, 종류입니다. 그러나 작성한 코드를 사용하면 두 번째 줄의 파일 이름/액세스 파일 값을 인쇄 할 수 없습니다. 어떤 생각? – demokritos

+0

및 "귀하의 두 번째"의견은 연결된 이전 질문의 주제와 관련이 있습니다 ... 혼란 스럽습니다 ... – demokritos

+0

스트림에 파일 이름이 없습니다. 어쨌든 당신은 그것을 증명할 수 없습니다. 'ReadToEnd()'는 전체 스트림을 읽습니다. 그래서 전체 파일을 줄 단위로 출력하지 않습니다. 인쇄 라인이 필요한 경우에는 ReadLine()을 사용하십시오. 예를 들어야하는지 알려주세요. –