コード例 #1
0
        private static MoveResult ExecuteMove(MoveInput input, DirectoryExistsAction directoryExistsAction)
        {
            var destinationFolderPath = input.TargetDirectory;

            switch (directoryExistsAction)
            {
            case DirectoryExistsAction.Rename:
                var count = 1;
                while (System.IO.Directory.Exists(destinationFolderPath))
                {
                    destinationFolderPath = $"{destinationFolderPath}({count++})";
                }
                break;

            case DirectoryExistsAction.Overwrite:
                if (System.IO.Directory.Exists(destinationFolderPath))
                {
                    System.IO.Directory.Delete(destinationFolderPath, true);
                }
                break;

            case DirectoryExistsAction.Throw:     //Will throw if target folder exist
                break;
            }

            System.IO.Directory.Move(input.SourceDirectory, destinationFolderPath);
            return(new MoveResult(destinationFolderPath, input.SourceDirectory));
        }
コード例 #2
0
        /// <summary>
        /// Moves a directory. By default will throw an error if the directory already exists. See https://github.com/FrendsPlatform/Frends.Directory
        /// </summary>
        /// <returns>Object { string TargetDirectory, string SourceDirectory }</returns>
        public static MoveResult Move([PropertyTab] MoveInput input, [PropertyTab] MoveOptions options)
        {
            if (!options.UseGivenUserCredentialsForRemoteConnections)
            {
                return(ExecuteMove(input, options.IfTargetDirectoryExists));
            }

            var domainAndUserName = GetDomainAndUserName(options.UserName);

            return(RunAsUser(domainAndUserName[0], domainAndUserName[1], options.Password, () =>
                             ExecuteMove(input, options.IfTargetDirectoryExists)));
        }