更改.zip的位置c#

时间:2013-07-10 19:25:07

标签: c#

这是我的代码:

    namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string appdata = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
            string subFolderPath = System.IO.Path.Combine(appdata, ".minecraft");
            string bin = System.IO.Path.Combine(subFolderPath, "bin");
            string mods = System.IO.Path.Combine(subFolderPath, "mods");
            string coremods =System.IO.Path.Combine(subFolderPath, "coremods");
            string config = System.IO.Path.Combine(subFolderPath, "config");
            if (Directory.Exists(mods)) Directory.Delete(mods,true);
            if (Directory.Exists(config)) Directory.Delete(config, true);
            if (Directory.Exists(coremods)) Directory.Delete(coremods, true);




            FastZip fZip1 = new FastZip();
            fZip1.ExtractZip(@"C:\Users\Rafa\Desktop\MagicFarm.zip", subFolderPath, "config");


            FastZip fZip = new FastZip();
            fZip.ExtractZip(@"C:\Users\Rafa\Desktop\MagicFarm.zip", subFolderPath, "mods");

            FastZip fZip2 = new FastZip();
            fZip2.ExtractZip(@"C:\Users\Rafa\Desktop\MagicFarm.zip", subFolderPath, "coremods");

我想将“C:\ Users \ Rafa \ Desktop \ MagicFarm.zip”放在项目目录中。

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:8)

看看File.Move,这可能会有所帮助;)

答案 1 :(得分:2)

您需要使用File.Move。这也向您展示了如何获取程序所在的当前目录。

//your zip
string sourceFile = @"C:\Users\Rafa\Desktop\MagicFarm.zip";
//the current directory that your exe is running from + the name
string destinationFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MagicFarm.zip")

// To move a file or folder to a new location:
System.IO.File.Move(sourceFile, destinationFile);