Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改.zip c的位置#_C# - Fatal编程技术网

C# 更改.zip c的位置#

C# 更改.zip c的位置#,c#,C#,这是我的密码: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string appdata = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); string

这是我的密码:

    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”放在项目目录中


有人能帮我吗?

看一看,这可能会有帮助;)

您将要使用
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);

当你说“项目目录”是什么意思?是否希望程序检查运行程序的文件夹以查找zip?或者,您的意思是希望zip与exe一起分发,以便运行exe提取zip?请记住,一旦编译了程序,它就不知道原始源代码文件保存在何处。它唯一能够保存ZIP文件的地方就是EXE所在的文件夹。你应该使用Path.Combine vs.“Path”+“file”你很接近,但我认为他不想从桌面移动到程序正在运行的文件夹,他想在程序运行时所在的文件夹中查找zip,而不在桌面路径中进行硬编码。你的
destinationFile
变量就是他真正想要的。花点时间看看程序在做什么,它正在将一个zip文件解压缩到Minecraft安装目录,他只是在寻找一种方法,让程序移动到另一台计算机上,并且仍然解压缩。