如何在Julia中重命名文件?

4

我目前有一组没有文件夹结构的图像数据集。然而,基于现有的图像名称,我想将文件重命名并移动到不同的文件夹结构中(假设文件夹存在,我也可以通过编程方式创建文件夹)。

在Python中,我可以只需重命名文件即可将其移动到我指定的更新位置。那么在Julia中如何重命名文件呢?


1个回答

5
在Julia的基本文件系统中,有一个mv命令,您可以使用它来移动和重命名文件,如下所示:
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> 

您可以在Julia文档中了解有关mv函数的更多信息


1
./test/hello.txt 中不需要添加 ./。它可以直接写成 test/hello.txt - Kristoffer Carlsson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接