0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Juliaで学ぶプログラミング入門 ファイル関連/ファイル移動・上書き

Last updated at Posted at 2022-12-11

ファイルの移動

Juliaを使ってファイルを移動するには、mvコマンドを使用します。

# ファイルを新しい場所に移動
mv(from, to)

例えば、/path/to/old/file.txtというファイルを、/path/to/new/file.txtという場所に移動したい場合は、次のようにします。

mv("/path/to/old/file.txt", "/path/to/new/file.txt")

なお、移動先の名前を変更したい場合は名前を変えてください。

上書きしたい場合

また、移動先に同じ名前のファイルが存在する場合の上書きは以下です。
force=trueとする必要があります。

# ファイルを新しい場所に移動し、上書き
mv(from, to, force=true)

例えば、/path/to/old/file.txtというファイルを、/path/to/new/file.txtという場所に移動したい場合は、次のようにします。

mv("/path/to/old/file.txt", "/path/to/new/file.txt", force=true)

この場合、/path/to/new/file.txtという場所に既に同じ名前のファイルが存在する場合、上書きされます。

上書きしない場合

もし上書きしたくない場合は、force=falseとするか、前述のとおり省略します。

# ファイルを移動し、上書きしない
mv("/path/to/old/file.txt", "/path/to/new/file.txt", force=false)
# ファイルを移動し、上書きしない
mv("/path/to/old/file.txt", "/path/to/new/file.txt")
これらの方法で、ファイルを移動し、かつ上書きすることができます。

※2022.12 julia1.7の解説です。

参考図書

1から始めるプログラミング

Juliaプログラミングクックブック

天才プログラマー タンメイが教える Julia超入門

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?