Databricks dbutils.fs.cp

1k views Asked by At

I am using dbutils.fs.cp(sourcefilepath,destinationfilepath) query to copy a file from one location to another from the azure storages.My source file path is /mnt/testing/StudentA/Test.csv and destination file path is /mnt/Testing_1/. in this case the dbutils is running but in the destination it creates a file with a folder name(StudentA) also it creates a folder called StudentA and place the Test.csv.

1

There are 1 answers

0
Rakesh Govindula On

I agree with @Chen Hirsh.

sourcefilepath="/mnt/testing/StudentA/mycsv2.csv"
destinationfilepath="/mnt/testing1"

dbutils.fs.cp(sourcefilepath,destinationfilepath)

This code won't copy the folder, it will only create a new mycsv2.csv file in the target location.

The folders copy as mentioned in your question will be copied like below only when you use recursive True in the code.

enter image description here

sourcefilepath="/mnt/testing"
destinationfilepath="/mnt/testing1/samp1/"

dbutils.fs.cp(sourcefilepath,destinationfilepath,True)

So, recheck your code and file paths. If you don't have any usage with source files, you can also try dbutils.fs.mv as a workaround.