Example #1
0
        //There is no difference between moving and renaming; you should simply call Directory.Move
        public void Move(string sourceDirName, string destDirName)
        {
            DataLakeDirectoryClient directoryClient = GetDirectoryClient(sourceDirName);
            var Names = _azureBlobAdapter.ExtractContainerBlobPortions(destDirName);

            directoryClient.Rename(NormalizeToBlobPath(Names.Item2));
        }
Example #2
0
        /// <summary>
        /// execute command
        /// </summary>
        public override void ExecuteCmdlet()
        {
            IStorageBlobManagement localChannel = Channel;

            bool foundAFolder = false;
            DataLakeFileClient      srcBlob    = null;
            DataLakeDirectoryClient srcBlobDir = null;

            if (ParameterSetName == ManualParameterSet)
            {
                DataLakeFileSystemClient fileSystem = GetFileSystemClientByName(localChannel, this.FileSystem);
                foundAFolder = GetExistDataLakeGen2Item(fileSystem, this.Path, out srcBlob, out srcBlobDir);
            }
            else //BlobParameterSet
            {
                if (!InputObject.IsDirectory)
                {
                    srcBlob = InputObject.File;
                }
                else
                {
                    srcBlobDir   = InputObject.Directory;
                    foundAFolder = true;
                }
            }

            if (foundAFolder)
            {
                if (ShouldProcess(GetDataLakeItemUriWithoutSas(srcBlobDir), "Move Directory: "))
                {
                    DataLakeFileSystemClient destFileSystem = GetFileSystemClientByName(localChannel, this.DestFileSystem != null ? this.DestFileSystem : this.FileSystem);
                    DataLakeDirectoryClient  destBlobDir    = destFileSystem.GetDirectoryClient(this.DestPath);

                    if (this.Force || !destBlobDir.Exists() || ShouldContinue(string.Format("Overwrite destination {0}", GetDataLakeItemUriWithoutSas(destBlobDir)), ""))
                    {
                        destBlobDir = srcBlobDir.Rename(this.DestPath, this.DestFileSystem).Value;
                        WriteDataLakeGen2Item(localChannel, destBlobDir);
                    }
                }
            }
            else
            {
                if (ShouldProcess(GetDataLakeItemUriWithoutSas(srcBlob), "Move File: "))
                {
                    DataLakeFileSystemClient destFileSystem = GetFileSystemClientByName(localChannel, this.DestFileSystem != null ? this.DestFileSystem : this.FileSystem);
                    DataLakeFileClient       destFile       = destFileSystem.GetFileClient(this.DestPath);

                    if (this.Force || !destFile.Exists() || ShouldContinue(string.Format("Overwrite destination {0}", GetDataLakeItemUriWithoutSas(destFile)), ""))
                    {
                        destFile = srcBlob.Rename(this.DestPath, this.DestFileSystem).Value;
                        WriteDataLakeGen2Item(localChannel, destFile);
                    }
                }
            }
        }
        public void Rename()
        {
            // Make StorageSharedKeyCredential to pass to the serviceClient
            string storageAccountName = StorageAccountName;
            string storageAccountKey  = StorageAccountKey;
            Uri    serviceUri         = StorageAccountBlobUri;
            StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);

            // Create DataLakeServiceClient using StorageSharedKeyCredentials
            DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential);

            // Get a reference to a filesystem named "sample-filesystem-rename" and then create it
            DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-rename"));

            filesystem.Create();
            try
            {
                // Create a DataLake Directory to rename it later
                DataLakeDirectoryClient directoryClient = filesystem.GetDirectoryClient(Randomize("sample-directory"));
                directoryClient.Create();

                // Rename directory with new path/name and verify by making a service call (e.g. GetProperties)
                #region Snippet:SampleSnippetDataLakeFileClient_RenameDirectory
                DataLakeDirectoryClient renamedDirectoryClient = directoryClient.Rename("sample-directory2");
                #endregion Snippet:SampleSnippetDataLakeFileClient_RenameDirectory
                PathProperties directoryPathProperties = renamedDirectoryClient.GetProperties();

                // Delete the sample directory using the new path/name
                filesystem.DeleteDirectory("sample-directory2");

                // Create a DataLake file.
                DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file"));
                fileClient.Create();

                // Rename file with new path/name and verify by making a service call (e.g. GetProperties)
                #region Snippet:SampleSnippetDataLakeFileClient_RenameFile
                DataLakeFileClient renamedFileClient = fileClient.Rename("sample-file2");
                #endregion Snippet:SampleSnippetDataLakeFileClient_RenameFile
                PathProperties filePathProperties = renamedFileClient.GetProperties();

                // Delete the sample directory using the new path/name
                filesystem.DeleteFile("sample-file2");
            }
            finally
            {
                // Clean up after the test when we're finished
                filesystem.Delete();
            }
        }