简体   繁体   English

File.Move =路径?

[英]File.Move = path?

Good morning, I should solve this problem. 早上好,我应该解决这个问题。 file.move locates a local path on my pc. file.move在我的电脑上找到本地路径。 if I had to move it to another pc this would not work because the paths are different. 如果必须将其移动到另一台PC,则将无法正常工作,因为路径不同。 there is a method for entering a unique path: File.move ("C: \\ Desktop \\ myfile", "C: \\ Desktop \\ myfolder \\ myfile") thanks for help 有一种输入唯一路径的方法:File.move(“ C:\\ Desktop \\ myfile”,“ C:\\ Desktop \\ myfolder \\ myfile”)感谢您的帮助

if (comboBox1.SelectedIndex == 0)
{
    label2.Text = "Download in corso";
    WebClient client = new WebClient();
    string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
    client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
    client.DownloadFileAsync(new Uri("http://www.homebrewsrv.altervista.org/OresteTool/trucchi/10%20in%201%20Arcade%20Collection%20EUR.rar"), desktop + "/ " + "10 in 1 Arcade Collection EUR.rar");
    System.Threading.Thread.Sleep(2000);
    Directory.CreateDirectory(@"C:\\Users\\orest\\Desktop\\zazza");
    System.Threading.Thread.Sleep(3000);
    File.Move("C: \\Users\\orest\\Desktop\\ 10 in 1 Arcade Collection EUR.rar", "C: \\Users\\orest\\Desktop\\zazza\\10 in 1 Arcade Collection EUR.rar");

}

Not sure what your error message is but i do notice some errors. 不知道您的错误消息是什么,但我确实注意到一些错误。

The first error is this line: 第一个错误是此行:

Directory.CreateDirectory(@"C:\\Users\\orest\\Desktop\\zazza");

If you start a string with @ you are telling it not to escape your characters, so you should change this to one of the following: 如果以@开头的字符串告诉您不要转义字符,则应将其更改为以下之一:

Directory.CreateDirectory("C:\\Users\\orest\\Desktop\\zazza");

or 要么

Directory.CreateDirectory(@"C:\Users\orest\Desktop\zazza");

Then you have an unnecessary sleep but i guess you know that.. 那你有不必要的睡眠,但我想你知道。

            System.Threading.Thread.Sleep(3000);

Then there is this line which have some whitespaces in the incorrect places, change this to: 然后是此行,在不正确的地方有一些空格,请将其更改为:

File.Move("C:\\Users\\orest\\Desktop\\10 in 1 Arcade Collection EUR.rar", "C:\\Users\\orest\\Desktop\\zazza\\10 in 1 Arcade Collection EUR.rar");

Then it should work, or you could skip the escaping (\\) and just use one but then you need the @ sign in the beginning. 然后它应该可以工作,或者您可以跳过转义(\\)并只使用一个,但是在开始时需要@符号。

But.... you are using DownloadFileAsync so you need to handle this correctly, if you dont know what that is i suggest you change your example to the following: 但是...。您正在使用DownloadFileAsync,因此您需要正确处理此问题,如果您不知道那是什么,我建议您将示例更改为以下内容:

if (comboBox1.SelectedIndex == 0)
{
    label2.Text = "Download in corso";
    WebClient client = new WebClient();
    string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    client.DownloadFile("http://www.homebrewsrv.altervista.org/OresteTool/trucchi/10%20in%201%20Arcade%20Collection%20EUR.rar", desktop + "/ " + "10 in 1 Arcade Collection EUR.rar");
    Directory.CreateDirectory("C:\\Users\\orest\\Desktop\\zazza");
    File.Move("C:\\Users\\orest\\Desktop\\10 in 1 Arcade Collection EUR.rar", "C:\\Users\\orest\\Desktop\\zazza\\10 in 1 Arcade Collection EUR.rar");
}

This is not async but you should read up on that. 这不是异步的,但您应该仔细阅读。 Also you could download directly to your zazza directory instead of moving there later on but again i am guessing there is some reason for this. 您也可以直接下载到您的zazza目录,而不是稍后再移动到该目录,但是我想这是有一定原因的。

If this dont work, please provide an error message and tell us exactly what you are trying to do. 如果此方法不起作用,请提供错误消息,并告诉我们您要执行的操作。

this script works only locally on my PC. 该脚本仅在我的PC上本地工作。 if you want to import this feature on another pc will not work because probably the other pc will not be called "C: \\\\ Users \\\\ orest \\\\ Desktop \\\\" etc .. 如果您想在另一台PC上导入此功能将无法正常工作,因为另一台PC可能不会被称为"C: \\\\ Users \\\\ orest \\\\ Desktop \\\\" etc ..

basically if the other pc is called "C: \\\\ Users \\\\ mypc \\\\ Desktop \\\\" etc..ecc. 基本上,如果另一台PC称为"C: \\\\ Users \\\\ mypc \\\\ Desktop \\\\" etc..ecc. this does not work. 这行不通。

it would serve a unique path of the type: 它会提供以下类型的唯一路径:

File.Move ("C: \\ Desktop \\ 10 in 1 Arcade Collection EUR.rar", "C: \\ Desktop \\ zazza \\ 10 in 1 Arcade Collection EUR.rar");

I hope to have explained to you correctly, forgive my bad c #, you will notice that they are the first weapons. 我希望正确地向您解释,原谅我的C#错误,您会注意到它们是第一把武器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM