コード例 #1
0
ファイル: CdCommand.cs プロジェクト: SneWs/Commander
        public string Execute(ICommandAccess access, string[] arguments)
        {
            if (arguments.Length < 1)
            {
                return access.WorkingDirectory;
            }

            string folder = arguments[0];

            // Special case handing for ~ (user home)
            if (folder == "~")
            {
                folder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            }

            string dir = Path.GetFullPath(Path.Combine(access.WorkingDirectory, folder));
            if (!Directory.Exists(dir))
            {
                return String.Format("Bad path/folder: '{0}' does not exist", dir);
            }

            access.SetDirectory(dir);
            return dir;
        }
コード例 #2
0
ファイル: CommandManager.cs プロジェクト: SneWs/Commander
        private static bool HandleChangeDriveCommand(string command, ICommandAccess commandAccess)
        {
            command = command.Trim();

            // Test for a drive path only such as C: or D:)
            if (command.Length <= 3 && (command.EndsWith(":") || command.EndsWith("\\")))
            {
                DriveInfo[] drives = DriveInfo.GetDrives();
                var driveInfo = drives.Where(x => x.Name.StartsWith(command)).FirstOrDefault();
                if (driveInfo != null)
                {
                    commandAccess.SetDirectory(driveInfo.RootDirectory.FullName);
                    commandAccess.AppendOutput("", true, true);
                    return true;
                }
            }

            return false;
        }