Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a file in Julia?

Tags:

julia

I currently have a dataset of images with no folder structure. However, based on the existing image name, I want to rename and move the file to a different folder structure (assuming the folders exist, I can also just make the folder programmatically).

In Python, I can just rename the file and it will move to the updated location I specify. How can I rename a file in Julia?

like image 644
logankilpatrick Avatar asked Nov 15 '25 16:11

logankilpatrick


1 Answers

In Julia's base filesystem, there is an mv command which you can use to move and rename the file as follows:

julia> write("hello.txt", "world"); # here we create a text file.

julia> mv("hello.txt", "goodbye.txt") # we then move it, but the file stays in the same dir so it is just renamed from hello to goodbye.
"goodbye.txt"

julia> mv("goodbye.txt", "./test/hello.txt") # in this example, we actually move the file from the existing folder into a new test folder as well as change the name.
"./test/hello.txt"

julia> 

You can read more about the mv function in the Julia docs.

like image 139
logankilpatrick Avatar answered Nov 17 '25 08:11

logankilpatrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!