Hi I am wondering how to copy folders into an existing folder in julia. In my case I have a folder called BigEarthNet-v1.0 which contains a number of sub-folders where each subfolder contains a number of tif files (i.e BigEarthNet-V1.0 -> [folder1, folder2, ...], where folder1 -> [image1.tif,image2.tif, ...]). I want to copy randomly 100 subfolders into an exiting folder called BigEarthNet-v1-concise. Literally make a concise dataset.
folders = readdir("BigEarthNet-v1.0")
random_paths = rand(folders, 100)
for folder in random_paths
cp(joinpath("BigEarthNet-v1.0",folder), "BigEarthNet-v1.0-concise", force = true)
end
If I don't enter force = true
i get an error. If I do the code works but literally only the last folder gets copied and it is also the files inside the folder rather than the folder itself. From what I am understand force =true
deletes the existing folder BigEarthNet-v1-concise
and recreates the folder again and this is why I get this behavior. Anyway to achieve what I am trying to do ?
You probably want something like:
The POSIX
cp
command behaves differently depending on if the target is an existing directory or not. This can make commands less verbose. Ifdir
is an existing directory:cp "$path" dir
is equivalent tocp "$path" "dir/$(basename "$path")"
This makes common usage in the shell less verbose but it is less explicit and a decision has been made not to replicate this behavior in Julia. See e.g. this issue.