トップ 差分 一覧 Farm ソース 検索 ヘルプ PDF RSS ログイン

list.files()

*disclaimer
178055

[R]

list.files()

  • ディレクトリー内のファイル一覧の取得
> list.files()
 [1] "CB17003-E.txt.tab"     "NS-E25"                "result.tab"            "test.txt.tab"          "ukou_all-rev.txt"      "ukou_all.txt"         
 [7] "ukouOK.txt"            "ukouOK_only.txt"       "VACs-rev-allfiles.Rmd" "VACs-rev.docx"         "VACs-rev.Rmd"          "VACs.Rmd"             
[13] "VACs.Rproj"  

  • ファイル名の文字列パターンによる指定オプション: pattern = "文字列"
list.files(pattern = ".txt"
    • 拡張子ではなく、文字列なので、ファイル名中にあるものはすべて該当する点に注意
 list.files(pattern = ".txt")
[1] "CB17003-E.txt.tab" "test.txt.tab"      "ukou_all-rev.txt"  "ukou_all.txt"      "ukouOK.txt"        "ukouOK_only.txt"  

  • サブディレクトリー内も再帰的にするオプション: recursive = TRUE
    • サブディレクトリーをパスとしてファイル名につけてくれる。
> list.files(recursive =T)
 [1] "CB17003-E.txt.tab"     "NS-E25/CB17001-E.txt"  "NS-E25/CB17003-E.txt"  "NS-E25/CB17007-E.txt"  "NS-E25/CB17009-E.txt"  "NS-E25/CB17011-E.txt" 
 [7] "NS-E25/CB17013-E.txt"  "NS-E25/CB17017-E.txt"  "NS-E25/CB17023-E.txt"  "NS-E25/CB17027-E.txt"  "NS-E25/CB17029-E.txt"  "NS-E25/CB17037-E.txt" 
[13] "NS-E25/CB17043-E.txt"  "NS-E25/CB17049-E.txt"  "NS-E25/CB17053-E.txt"  "NS-E25/CB17059-E.txt"  "NS-E25/CB17061-E.txt"  "NS-E25/CB17063-E.txt" 
[19] "NS-E25/CB17067-E.txt"  "NS-E25/CB17069-E.txt"  "NS-E25/CB17071-E.txt"  "NS-E25/CB17073-E.txt"  "NS-E25/CB17075-E.txt"  "NS-E25/CB17077-E.txt" 
[25] "NS-E25/CB17079-E.txt"  "NS-E25/CB17083-E.txt"  "result.tab"            "test.txt.tab"          "ukou_all-rev.txt"      "ukou_all.txt"         
[31] "ukouOK.txt"            "ukouOK_only.txt"       "VACs-rev-allfiles.Rmd" "VACs-rev.docx"         "VACs-rev.Rmd"          "VACs.Rmd"             
[37] "VACs.Rproj" 

> list.files(pattern=".txt", recursive=T)
 [1] "CB17003-E.txt.tab"    "NS-E25/CB17001-E.txt" "NS-E25/CB17003-E.txt" "NS-E25/CB17007-E.txt" "NS-E25/CB17009-E.txt" "NS-E25/CB17011-E.txt"
 [7] "NS-E25/CB17013-E.txt" "NS-E25/CB17017-E.txt" "NS-E25/CB17023-E.txt" "NS-E25/CB17027-E.txt" "NS-E25/CB17029-E.txt" "NS-E25/CB17037-E.txt"
[13] "NS-E25/CB17043-E.txt" "NS-E25/CB17049-E.txt" "NS-E25/CB17053-E.txt" "NS-E25/CB17059-E.txt" "NS-E25/CB17061-E.txt" "NS-E25/CB17063-E.txt"
[19] "NS-E25/CB17067-E.txt" "NS-E25/CB17069-E.txt" "NS-E25/CB17071-E.txt" "NS-E25/CB17073-E.txt" "NS-E25/CB17075-E.txt" "NS-E25/CB17077-E.txt"
[25] "NS-E25/CB17079-E.txt" "NS-E25/CB17083-E.txt" "test.txt.tab"         "ukou_all-rev.txt"     "ukou_all.txt"         "ukouOK.txt"          
[31] "ukouOK_only.txt"