mssparkutils.fs.mv doesn't create new folder if it doesn't exists

Raghul Kannan 191 Reputation points
2023-07-26T08:39:45.8166667+00:00

Hi,

I'm using

mssparkutils.fs.mv("abfss://******@storageaccount.dfs.core.net/folder1/test.csv","abfss://******@storageaccount.dfs.core.net/folder2",True) to move a file from folder1 to folder2. However, folder2 isn't getting created if it doesn't exist. For some reason, "file" called "folder2" is created.

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
{count} votes

Accepted answer
  1. Bhargava-MSFT 31,261 Reputation points Microsoft Employee Moderator
    2023-07-31T17:49:43.6066667+00:00

    Hello Raghul Kannan,

    <update>

    PG confirmed this is expected behavior. Since the mv API treats mv test.csv to another file folder2.

    You can either use the "destination file path" or make sure folder2 already exists or use mv API like below.

    mssparkutils.fs.mv("abfss://******@storageaccount.dfs.core.net/folder1/test.csv","abfss://******@storageaccount.dfs.core.net/folder2/test.csv",True)

     PG is going to update the documentation:  ‘destination directory’, to "destination file path" on the below command.

    mssparkutils.fs.mv('source file or directory', 'destination directory', True) # Set the last parameter as True to firstly create the parent directory if it does not exist

    I hope this answers your question.

    Please let me know if you have any further questions.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.