GetByName() 공개 메소드

public GetByName ( String name ) : File
name String
리턴 System.IO.File
예제 #1
0
파일: CommandFileIO.cs 프로젝트: itsbth/KOS
        public override void Evaluate()
        {
            String targetFile = RegexMatch.Groups[1].Value.Trim();
            String operation  = RegexMatch.Groups[3].Value.Trim().ToUpper();
            String volumeName = RegexMatch.Groups[5].Value.Trim();
            File   file       = null;

            Volume targetVolume = null;

            switch (operation)
            {
            case "FROM":
                targetVolume = GetVolume(volumeName);     // Will throw if not found
                file         = targetVolume.GetByName(targetFile);
                if (file == null)
                {
                    throw new kOSException("File '" + targetFile + "' not found");
                }
                targetVolume.DeleteByName(targetFile);
                break;

            default:
                file = SelectedVolume.GetByName(targetFile);
                if (file == null)
                {
                    throw new kOSException("File '" + targetFile + "' not found");
                }
                SelectedVolume.DeleteByName(targetFile);
                break;
            }

            State = ExecutionState.DONE;
        }
예제 #2
0
        public override void Evaluate()
        {
            String targetFile = RegexMatch.Groups[1].Value.Trim();
            String volumeName = RegexMatch.Groups[3].Value.Trim();

            File   file         = null;
            Volume targetVolume = null;

            if (volumeName.Trim() != "")
            {
                targetVolume = GetVolume(volumeName); // Will throw if not found
                file         = targetVolume.GetByName(targetFile);
                if (file == null)
                {
                    throw new kOSException("File '" + targetFile + "' not found", this);
                }
                targetVolume.DeleteByName(targetFile);
            }
            else
            {
                file = SelectedVolume.GetByName(targetFile);
                if (file == null)
                {
                    throw new kOSException("File '" + targetFile + "' not found", this);
                }
                SelectedVolume.DeleteByName(targetFile);
            }

            State = ExecutionState.DONE;
        }
예제 #3
0
파일: Function.cs 프로젝트: erendrake/kRISC
        public override void Execute(SharedObjects shared)
        {
            string newName = shared.Cpu.PopValue().ToString();
            object oldName = shared.Cpu.PopValue();
            string objectToRename = shared.Cpu.PopValue().ToString();

            if (shared.VolumeMgr != null)
            {
                if (objectToRename == "file")
                {
                    Volume volume = shared.VolumeMgr.CurrentVolume;
                    if (volume != null)
                    {
                        if (volume.GetByName(newName) == null)
                        {
                            if (!volume.RenameFile(oldName.ToString(), newName))
                            {
                                throw new Exception(string.Format("File '{0}' not found", oldName.ToString()));
                            }
                        }
                        else
                        {
                            throw new Exception(string.Format("File '{0}' already exists.", newName));
                        } 
                    }
                    else
                    {
                        throw new Exception("Volume not found");
                    }
                }
                else
                {
                    Volume volume = shared.VolumeMgr.GetVolume(oldName);
                    if (volume != null)
                    {
                        if (volume.Renameable)
                        {
                            volume.Name = newName;
                        }
                        else
                        {
                            throw new Exception("Volume cannot be renamed");
                        }
                    }
                    else
                    {
                        throw new Exception("Volume not found");
                    }
                }
            }
        }
예제 #4
0
        public override void Evaluate()
        {
            String targetFile = RegexMatch.Groups[1].Value.Trim();
            String volumeName = RegexMatch.Groups[4].Value.Trim();
            String operation  = RegexMatch.Groups[2].Value.Trim().ToUpper();

            Volume targetVolume = GetVolume(volumeName); // Will throw if not found

            File file = null;

            switch (operation)
            {
            case "FROM":
                file = targetVolume.GetByName(targetFile);
                if (file == null)
                {
                    throw new kOSException("File '" + targetFile + "' not found", this);
                }
                if (!SelectedVolume.SaveFile(new File(file)))
                {
                    throw new kOSException("File copy failed", this);
                }
                break;

            case "TO":
                file = SelectedVolume.GetByName(targetFile);
                if (file == null)
                {
                    throw new kOSException("File '" + targetFile + "' not found", this);
                }
                if (!targetVolume.SaveFile(new File(file)))
                {
                    throw new kOSException("File copy failed", this);
                }
                break;
            }

            State = ExecutionState.DONE;
        }