如何实现安装程序自动将一个目录拷贝到C盘根目录下?

时间:2021-06-13 19:06:21
想实现这样的安装程序:
安装的时候,将安装包中的一个目录及此目录下的所有内容拷贝到C盘根目录中
请问该如何实现?

6 个解决方案

#1


在安装包里的目录及文件系统会自动的安装到安装目录里的.

#2


实在不行可以添加自定义的安装操作类.

#3


沒錯,利用.NET自帶的安裝部署程序就可以。

#4


解释一下,是要安装的过程中拷贝到C盘根目录下,而不是程序默认的安装目录下

#5


用DirectoryInfo类吧

using System;
using System.IO;

public class MoveToTest 
{
    public static void Main() 
    {

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");

        // Move the main directory. Note that the contents move with the directory.
        if (Directory.Exists("NewTempDir") == false)
            di.MoveTo("NewTempDir");

        try 
        {
            // Attempt to delete the subdirectory. Note that because it has been
            // moved, an exception is thrown.
            dis.Delete(true);
        } 
        catch (Exception) 
        {
            // Handle this exception in some way, such as with the following code:
            // Console.WriteLine("That directory does not exist.");
        }

        // Point the DirectoryInfo reference to the new directory.
        //di = new DirectoryInfo("NewTempDir");

        // Delete the directory.
        //di.Delete(true);
    }
}

#6


添加一个安装操作类,然后在Install方法里面用上面的代码

#1


在安装包里的目录及文件系统会自动的安装到安装目录里的.

#2


实在不行可以添加自定义的安装操作类.

#3


沒錯,利用.NET自帶的安裝部署程序就可以。

#4


解释一下,是要安装的过程中拷贝到C盘根目录下,而不是程序默认的安装目录下

#5


用DirectoryInfo类吧

using System;
using System.IO;

public class MoveToTest 
{
    public static void Main() 
    {

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");

        // Move the main directory. Note that the contents move with the directory.
        if (Directory.Exists("NewTempDir") == false)
            di.MoveTo("NewTempDir");

        try 
        {
            // Attempt to delete the subdirectory. Note that because it has been
            // moved, an exception is thrown.
            dis.Delete(true);
        } 
        catch (Exception) 
        {
            // Handle this exception in some way, such as with the following code:
            // Console.WriteLine("That directory does not exist.");
        }

        // Point the DirectoryInfo reference to the new directory.
        //di = new DirectoryInfo("NewTempDir");

        // Delete the directory.
        //di.Delete(true);
    }
}

#6


添加一个安装操作类,然后在Install方法里面用上面的代码