LoginSignup
3
2

More than 5 years have passed since last update.

gzipなtarファイルを一括に解凍する方法 [R]

Posted at

はじめに

とある衛星画像を扱おうとしたらgzipファイルとして圧縮されたtarファイルで一括解凍するために四苦八苦した時の忘備録。

実行

作業ディレクトリ(Rstudioではプロジェクトが保存されているところがデフォルト)に対象ファイルを入れておくようの"input"というフォルダを作成しておきます。このとき必要なデータは全て入れておきましょう。

> list.files("input")
[1] "test.tar.gz"  "test2.tar.gz" "test3.tar.gz"

解凍するための関数は'untar'になります。
これを使用して、"input"内にあるファイルをforループにより解凍します。

#uncompression
files <- list.files("input")

for (file in files) {
  untar(paste0("input/", file))
}

ご参考になれば幸いです。
またこの場合、結果が出力されるのが作業ディレクトリになります。うまく出力先を指定できる方法を教えていただければ幸いです。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2