示例#1
0
        private static RenameResult ExecuteRename(RenameInput input, FileExistsAction fileExistsAction)
        {
            var directoryPath   = Path.GetDirectoryName(input.Path);
            var newFileFullPath = Path.Combine(directoryPath, input.NewFileName);

            switch (fileExistsAction)
            {
            case FileExistsAction.Rename:
                newFileFullPath = GetNonConflictingDestinationFilePath(input.Path, newFileFullPath);
                break;

            case FileExistsAction.Overwrite:
                if (System.IO.File.Exists(newFileFullPath))
                {
                    System.IO.File.Delete(newFileFullPath);
                }
                break;

            case FileExistsAction.Throw:
                if (System.IO.File.Exists(newFileFullPath))
                {
                    throw new IOException($"File already exists {newFileFullPath}. No file renamed.");
                }
                break;
            }
            System.IO.File.Move(input.Path, newFileFullPath);
            return(new RenameResult(newFileFullPath));
        }
示例#2
0
 /// <summary>
 /// Rename a single file. See: https://github.com/FrendsPlatform/Frends.File#Rename
 /// </summary>
 ///  <returns>Object { string Path }</returns>
 public static RenameResult Rename([PropertyTab] RenameInput input, [PropertyTab] RenameOption options)
 {
     return(ExecuteAction(() => ExecuteRename(input, options.RenameBehaviour), options.UseGivenUserCredentialsForRemoteConnections, options.UserName, options.Password));
 }