Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy a file in Julia?

Tags:

julia

I am trying to copy a file using Julia functions with the hope of manipulating the file and then use that copied version for various tasks in the Julia programming language. Can someone provide some example code of copying a file in Julia?

I guess I could do use read then write but it seems like I would be reinventing the wheel. Is there a standard library function for this?

Inspired by this question.

like image 828
logankilpatrick Avatar asked Sep 29 '19 00:09

logankilpatrick


People also ask

How to write a file in Julia?

We can write in an existing file in Julia by using the write(fileobject, string) method. To write in a file, we need to open the file in write mode. To do so, we have to pass "w" in the mode argument. The most important step while writing a file is to close the file after the computation.

How do you save in Julia?

Julia – Save Plot as PNG or JPEG To save a plot to local file storage, use the method savefig("filename") or png("filename") .

How do I get the current working directory in Julia?

See also: cd , tempdir . Set the current working directory. See also: pwd , mkdir , mkpath , mktempdir . Temporarily change the current working directory to dir , apply function f and finally return to the original directory.


1 Answers

Just use the built in function cp(src, dst).

Copy the file, link, or directory from src to dst. force=true will first remove an existing dst.

Afterwards you can open the file and manipulate it. Of course you could also open both source an destination files simultaneously and copy and manipulate it line by line.

like image 88
carstenbauer Avatar answered Oct 21 '22 05:10

carstenbauer