当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.MoveTo方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.MoveTo方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.MoveTo方法的具体用法?C# DirectoryInfo.MoveTo怎么用?C# DirectoryInfo.MoveTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.MoveTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OPMShellTreeView_AfterLabelEdit

        void OPMShellTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.Label))
            {
                string newName = e.Label;
                DirectoryInfo di = new DirectoryInfo(e.Node.FullPath);
                if (di != null && di.Exists && di.Parent != null && di.Parent.Exists)
                {
                    string newPath = Path.Combine(di.Parent.FullName, newName);

                    try
                    {
                        di.MoveTo(newPath);
                        e.Node.Name = di.Name;
                        e.Node.Tag = di;
                        e.CancelEdit = false;

                        SelectedNode = null;
                        SelectedNode = e.Node;

                        return;
                    }
                    catch { }
                }
            }

            e.CancelEdit = true;
        }
开发者ID:rraguso,项目名称:protone-suite,代码行数:28,代码来源:OPMShellTreeView.cs

示例2: DeleteFolder

 public override void DeleteFolder(DirectoryInfo info, bool recursive)
 {
     if (!recursive && info.GetFileSystemInfos().Length != 0)
     throw new InvalidOperationException(S._("The folder {0} cannot be deleted as it is " +
      "not empty."));
        foreach (DirectoryInfo dir in info.GetDirectories())
     DeleteFolder(dir);
        foreach (FileInfo file in info.GetFiles())
     DeleteFile(file);
        for (int i = 0; i < FileNameErasePasses; ++i)
        {
     string newPath = GenerateRandomFileName(info.Parent, info.Name.Length);
     try
     {
      info.MoveTo(newPath);
     }
     catch (IOException)
     {
      Thread.Sleep(100);
      --i;
     }
        }
        info.CreationTime = info.LastWriteTime = info.LastAccessTime = MinTimestamp;
        info.Delete(true);
 }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:25,代码来源:Windows.cs

示例3: btn_MoveDir_Click

 private void btn_MoveDir_Click(object sender, EventArgs e)
 {
     string strPath1 = this.txt_Path1.Text;
     string strPath2 = this.txt_Path2.Text;
     DirectoryInfo dirInfo = new DirectoryInfo(strPath1);
     dirInfo.MoveTo(strPath2);
 }
开发者ID:siyongshuai,项目名称:winformBasic,代码行数:7,代码来源:Form1.cs

示例4: dirRename

        public void dirRename(DirectoryInfo incDir)
        {
            string newDir = incDir.Name,
                oldDir = incDir.FullName;

            parseAll(ref newDir);

            newDir = Path.Combine(incDir.Parent.FullName, newDir);

            if (newDir == oldDir)
                return;

            if (!Directory.Exists(newDir))
                try
                {
                    incDir.MoveTo(newDir);

                    if (flgVerbose)
                        Console.WriteLine(String.Format("{0} -->> {1}", oldDir, newDir));
                }
                catch { Console.WriteLine(String.Format("Error: unable to rename, check permissions: {0}", incDir.FullName)); }
            else
                Console.WriteLine(String.Format("Error: directory already exists: {0}",
                    Path.Combine(incDir.Parent.FullName, newDir)));
        }
开发者ID:tanjera,项目名称:rname,代码行数:25,代码来源:Rname.cs

示例5: RenameUserProfile

        public static bool RenameUserProfile(string userProfileName, DirectoryInfo userDataDir, string newUserProfileName)
        {
            var isRenamed = false;

            if (userProfileName != null && userDataDir != null && newUserProfileName != null)
            {
                var src = new DirectoryInfo(userDataDir.FullName + "\\" + userProfileName);
                var dst = new DirectoryInfo(userDataDir.FullName + "\\" + newUserProfileName);

                try
                {
                    if (src.Parent != null)
                    {
                        if (src.Exists && !dst.Exists)
                        {
                            src.MoveTo(Path.Combine(src.Parent.FullName, newUserProfileName));
                        }

                        isRenamed = true;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            return isRenamed;
        }
开发者ID:peterboni,项目名称:ChromeDeck,代码行数:29,代码来源:UserProfileFunctions.cs

示例6: MoveFolderInsideTheWatchedFolder

        public void MoveFolderInsideTheWatchedFolder() {
            string oldName = Path.GetRandomFileName();
            string newName = Path.GetRandomFileName();
            using (FileSystemWatcher fsWatcher = new FileSystemWatcher(this.path)) {
                fsWatcher.IncludeSubdirectories = true;
                fsWatcher.Filter = "*";
                fsWatcher.InternalBufferSize = 4 * 1024 * 16;
                fsWatcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite | NotifyFilters.Security;
                fsWatcher.Created += (object sender, FileSystemEventArgs e) => this.list.Add(e);
                fsWatcher.Changed += (object sender, FileSystemEventArgs e) => this.list.Add(e);
                fsWatcher.Deleted += (object sender, FileSystemEventArgs e) => this.list.Add(e);
                fsWatcher.Renamed += (object sender, RenamedEventArgs e) => this.list.Add(e);
                DirectoryInfo dirA = new DirectoryInfo(Path.Combine(this.path, Path.GetRandomFileName()));
                dirA.Create();
                DirectoryInfo dirB = new DirectoryInfo(Path.Combine(this.path, Path.GetRandomFileName()));
                dirB.Create();
                DirectoryInfo movingDir = new DirectoryInfo(Path.Combine(dirA.FullName, oldName));
                movingDir.Create();
                fsWatcher.EnableRaisingEvents = true;
                movingDir.MoveTo(Path.Combine(dirB.FullName, newName));
                while (this.list.Count < 2) {
                    Thread.Sleep(100);
                }

                Assert.That(this.list.Count, Is.GreaterThanOrEqualTo(2));
                Assert.That(this.list[0].ChangeType, Is.EqualTo(WatcherChangeTypes.Deleted));
                Assert.That(this.list[0].FullPath, Is.EqualTo(Path.Combine(dirA.FullName, oldName)));
                Assert.That(this.list[1].ChangeType, Is.EqualTo(WatcherChangeTypes.Created));
                Assert.That(this.list[1].FullPath, Is.EqualTo(Path.Combine(dirB.FullName, newName)));
            }
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:31,代码来源:FileSystemEventOrderTest.cs

示例7: CopyDirectories

        public void CopyDirectories()
        {
            string destinationPath = Settings.Default.DestinationPath;
            string[] directories = Directory.GetDirectories(_desktopDirectory);

            foreach (string directory in directories)
            {
                string dirName = Path.GetFileName(directory);

                if (dirName != null)
                {
                    if (!IsBlacklistedDir(dirName))
                    {
                        string destinationDirectory = Path.Combine(destinationPath, dirName);

                        if (Directory.Exists(destinationDirectory))
                        {
                            int doubleCounter = Settings.Default.DoubleFileExtension;

                            string name = dirName;
                            name = name + "{" + doubleCounter + "}";

                            destinationDirectory = Path.Combine(destinationPath, name);

                            doubleCounter++;
                            Settings.Default.DoubleFileExtension = doubleCounter;
                        }

                        var info = new DirectoryInfo(directory);
                        info.MoveTo(destinationDirectory);
                    }
                }
            }
        }
开发者ID:sri-n,项目名称:DesktopCleaner,代码行数:34,代码来源:FileSystemService.cs

示例8: BeginModifying

 public static DirectoryInfoModifyingBegun BeginModifying(this DirectoryInfo orgInfo)
 {
     var id = Guid.NewGuid().ToString("N");
     var bakInfo = new DirectoryInfo(orgInfo.FullName);
     var bakPath = orgInfo.FullName + "." + id + ".bak";
     if (bakInfo.Exists)
         bakInfo.MoveTo(bakPath);
     return new DirectoryInfoModifyingBegun(orgInfo, bakPath);
 }
开发者ID:umaranis,项目名称:Prig,代码行数:9,代码来源:DirectoryInfoMixin.cs

示例9: MoveFolder

 /// <summary>
 /// Moves a folder to another destination.
 /// </summary>
 /// <param name="folderToMove">The folder to be moved.</param>
 /// <param name="destinationFolder">The destination folder to where the folder should be moved.</param>
 /// <param name="createDestinationFolder">Defines if the destination folder must be created if it doesn't exist.</param>
 /// <returns>A boolean indicating that the move was successful.</returns>
 public static bool MoveFolder(string folderToMove, string destinationFolder, bool createDestinationFolder)
 {
     if (Directory.Exists(folderToMove))
     {
         var dInfo = new DirectoryInfo(folderToMove);
         dInfo.MoveTo(PathHelper.ValidateEndOfPath(destinationFolder));
     }
     return true;
 }
开发者ID:Heyvaert,项目名称:global,代码行数:16,代码来源:IOHelper.cs

示例10: moveDatabaseLocations

    //[Repeat(3)]
    public void moveDatabaseLocations()
    {
      SessionBase.BaseDatabasePath = "d:/Databases"; // use same as VelocityDbServer.exe.config 
      DirectoryInfo info = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath,  systemDir));
     if (info.Exists)
        info.Delete(true);
      DirectoryInfo newInfo = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath,  systemDir + "MovedTo"));
      string newPath = newInfo.FullName;
      if (newInfo.Exists)
        newInfo.Delete(true);
      createDatabaseLocations(new SessionNoServer(systemDir));
      info.MoveTo(newPath);
      moveDatabaseLocations(new SessionNoServer(newPath, 2000, false, false), systemHost, newPath);
      verifyDatabaseLocations(new SessionNoServer(newPath));
      info.Delete(true);

      info = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath, systemDir));
      if (info.Exists)
        info.Delete(true);
      createDatabaseLocations(new ServerClientSession(systemDir));
      newPath = Path.Combine(SessionBase.BaseDatabasePath, systemDir + "MovedTo");
      info.MoveTo(newPath);
      moveDatabaseLocations(new ServerClientSession(newPath, systemHost, 2000, false, false), systemHost, newPath);
      verifyDatabaseLocations(new ServerClientSession(newPath, systemHost));
      info.Delete(true);

      info = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath, systemDir));
      if (info.Exists)
        info.Delete(true);
      string d = SessionBase.BaseDatabasePath;
      try
      {
        SessionBase.BaseDatabasePath = "\\\\" + systemHost2 + "\\Shared";
        newPath = Path.Combine(SessionBase.BaseDatabasePath, systemDir);
        info = new DirectoryInfo(newPath);
        createDatabaseLocations(new ServerClientSession(newPath, systemHost2));
        SessionBase.BaseDatabasePath = d;
        newPath = Path.Combine(SessionBase.BaseDatabasePath, systemDir + "MovedTo");
        string[] files = Directory.GetFiles(info.FullName);
        Directory.CreateDirectory(newPath);
        foreach (string file in files)
        {
          string name = Path.GetFileName(file);
          string dest = Path.Combine(newPath, name);
          File.Copy(file, dest);
        }
        info.Delete(true);
        info = new DirectoryInfo(newPath);
        moveDatabaseLocations(new ServerClientSession(newPath, systemHost, 2000, false, false), systemHost, newPath);
        verifyDatabaseLocations(new ServerClientSession(newPath));
        info.Delete(true);
      }
      finally
      {
        SessionBase.BaseDatabasePath = d;
      }
    }
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:58,代码来源:MoveDatabaseLocations.cs

示例11: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
                status = arr[0];
            else if (radioButton2.Checked)
                status = arr[1];
            else if (radioButton3.Checked)
                status = arr[2];
            else if (radioButton4.Checked)
                status = arr[3];
            else if (radioButton5.Checked)
                status = arr[4];
            else if (radioButton6.Checked)
                status = arr[5];

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {

                DirectoryInfo d = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
                string selectedpath = d.Parent.FullName + d.Name;
                if (folderBrowserDialog1.SelectedPath.LastIndexOf(".{") == -1)
                {
                    if (checkBox1.Checked)
                        setpassword(folderBrowserDialog1.SelectedPath);
                    if (!d.Root.Equals(d.Parent.FullName))
                    d.MoveTo(d.Parent.FullName + "\\" + d.Name + status);
                    else d.MoveTo(d.Parent.FullName + d.Name + status);
                    textBox1.Text = folderBrowserDialog1.SelectedPath;
                    pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\lock.jpg");
                }
                else
                {
                    status = getstatus(status);
                    bool s=checkpassword();
                    if (s)
                    {
                        File.Delete(folderBrowserDialog1.SelectedPath + "\\p.xml");
                        d.MoveTo(folderBrowserDialog1.SelectedPath.Substring(0, folderBrowserDialog1.SelectedPath.LastIndexOf(".")));
                        textBox1.Text = folderBrowserDialog1.SelectedPath.Substring(0, folderBrowserDialog1.SelectedPath.LastIndexOf("."));
                        pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\unlock.jpg");
                    }
                }
            }
        }
开发者ID:piyushkp,项目名称:WindowsFolderLock,代码行数:44,代码来源:Form1.cs

示例12: Execute

		/// <summary>
		/// ITestStep.Execute() implementation
		/// </summary>
		/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
		/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
		public void Execute(XmlNode testConfig, Context context)
		{
			string srcDirectory = context.ReadConfigAsString( testConfig, "SourceDirectory");
			string dstDirectory = context.ReadConfigAsString( testConfig, "DestinationDirectory");

			context.LogInfo("About to renme the directory \"{0}\" to \"{1}\"", srcDirectory, dstDirectory);

			var di = new DirectoryInfo(srcDirectory);
			di.MoveTo(dstDirectory);
		}
开发者ID:RobBowman,项目名称:BizUnit,代码行数:15,代码来源:RenameDirectoryStep.cs

示例13: Main

 public static void Main()
 {
     // ...
     DirectoryInfo directory = new DirectoryInfo(".\\Source");
     directory.MoveTo(".\\Root");
     DirectoryInfoExtension.CopyTo(
         directory, ".\\Target",
         SearchOption.AllDirectories, "*");
     // ...
 }
开发者ID:troubleminds,项目名称:TIP,代码行数:10,代码来源:Listing05.37.DefiningAStaticMethodOnDirectoryInfo.cs

示例14: button3_Click

 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         DirectoryInfo DInfo = new DirectoryInfo(textBox1.Text);//创建DirectoryInfo对象
         //设置移动路径
         string strPath = textBox2.Text + textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1, textBox1.Text.Length - textBox1.Text.LastIndexOf("\\") - 1);
         DInfo.MoveTo(strPath);//移动文件夹
     }
     catch { MessageBox.Show("移动的文件必须在同一盘符下!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
 }
开发者ID:TGHGH,项目名称:C-1200,代码行数:11,代码来源:Frm_Main.cs

示例15: MoveToDestination

        public void MoveToDestination(string target)
        {
            if (string.IsNullOrEmpty(target)) return;
            if (!Directory.Exists(target)) return;
            if (target == FullPath) return;

            DirectoryInfo folder = new DirectoryInfo(FullPath);
            var destination = Path.Combine(target, folder.Name);
            Console.WriteLine(string.Format("move {0} to {1}", FullPath, destination));
            folder.MoveTo(destination);
        }
开发者ID:topas,项目名称:warmup,代码行数:11,代码来源:TargetDir.cs


注:本文中的System.IO.DirectoryInfo.MoveTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。