示例#1
0
        public void MoveFile(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo fi = fs.GetFileInfo("foo.txt");

            using (Stream s = fi.Create())
            {
                for (int i = 0; i < 10; ++i)
                {
                    s.Write(new byte[111], 0, 111);
                }
            }
            fi.Attributes = FileAttributes.Hidden | FileAttributes.System;

            fi.MoveTo("foo2.txt");

            fi = fs.GetFileInfo("foo2.txt");
            Assert.True(fi.Exists);
            Assert.Equal(1110, fi.Length);
            Assert.Equal(FileAttributes.Hidden | FileAttributes.System, fi.Attributes);

            fi = fs.GetFileInfo("foo.txt");
            Assert.False(fi.Exists);
        }
示例#2
0
        protected override void RenameItem(string path, string newName)
        {
            object obj = FindItemByPath(Utilities.NormalizePath(path), true, false);

            DiscFileSystemInfo fsiObj = obj as DiscFileSystemInfo;

            if (fsiObj == null)
            {
                WriteError(new ErrorRecord(
                               new InvalidOperationException("Cannot move items to this location"),
                               "BadParentForNewItem",
                               ErrorCategory.InvalidArgument,
                               newName));
                return;
            }

            string newFullName = Path.Combine(Path.GetDirectoryName(fsiObj.FullName.TrimEnd('\\')), newName);

            if (obj is DiscDirectoryInfo)
            {
                DiscDirectoryInfo dirObj = (DiscDirectoryInfo)obj;
                dirObj.MoveTo(newFullName);
            }
            else
            {
                DiscFileInfo fileObj = (DiscFileInfo)obj;
                fileObj.MoveTo(newFullName);
            }
        }