'Trying to move a file from a Azure Data Lake folder to another

I have function app read the file from data lake and do some processing of the file content. If it failed it move the file to the "Error" folder. I tried this but was unsuccessful. Solution I tried SO-solution

public static async Task<DataLakeFileClient> MoveDirectory(string file)
{        
    DataLakeServiceClient serviceClient = await GetDataLakeClient(); 

    DataLakeFileSystemClient filesystemClient = 
    serviceClient.GetFileSystemClient(<CONTAINER>);
    
    DataLakeFileClient fileClient = 
    filesystemClient.GetFileClient("Provision/" + file);
    
    return await fileClient.RenameAsync("Provision/Error/" + file);
}

Cause a 404 SourcePathNotFound.

Any tips or advice how I can move files from one directory to another?



Solution 1:[1]

After making a few changes we could able to get this work. While using GetFileClient for the required file you need to use DataLakeFileSystemClient instead of DataLakeServiceClient. Below is the code that worked for me.

DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient("<CONNECTION STRING>");
DataLakeFileSystemClient dataLakeFileSystemClient = dataLakeServiceClient.GetFileSystemClient("<CONTAINER>");

DataLakeFileClient sourceDataLakeFileClient = dataLakeFileSystemClient.GetFileClient("provision/<FILENAME>");
return await sourceDataLakeFileClient.RenameAsync("provision/Error/<FILENAME>");

RESULTS:

Before execution

enter image description here

After execution

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SwethaKandikonda-MT