C# 未能找到 的一部分

2024-12-28 03:48:55
推荐回答(5个)
回答1:

//我把你的程序改动了一下,你只要选取你想要的就OK了,希望能够帮助你
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileCopyPath_WIN
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = Application.StartupPath;
}

private void button3_Click(object sender, EventArgs e)
{
button3.ForeColor = Color.BlueViolet;
button4.ForeColor = Color.Gold;
try
{
StreamWriter fs = new StreamWriter(Application.StartupPath + @"\Output.w");
fs.WriteLine("set realmlist tw.logon.worldofwarcraft.com");
fs.Flush();
fs.Close();

File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\\realmlist.wtf", true);

//因为Copy是复制到指定已存在的路径中,而不能自生成路径,所以要先创建路径··
string path1 = Application.StartupPath + "\\data";
Directory.CreateDirectory(path1);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\\realmlist.wtf", true);

string path2 = Application.StartupPath + "\\data\\zhTW";
Directory.CreateDirectory(path2);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\zhTW\\realmlist.wtf", true);




MessageBox.Show("DONE!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}

回答2:

//我把你的程序改动了一下,只要选取想要的就OK了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileCopyPath_WIN
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = Application.StartupPath;
}

private void button3_Click(object sender, EventArgs e)
{
button3.ForeColor = Color.BlueViolet;
button4.ForeColor = Color.Gold;
try
{
StreamWriter fs = new StreamWriter(Application.StartupPath + @"\Output.w");
fs.WriteLine("set realmlist tw.logon.worldofwarcraft.com");
fs.Flush();
fs.Close();

File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\\realmlist.wtf", true);

//因为Copy是复制到指定已存在的路径中,而不能自生成路径,所以要先创建路径··
string path1 = Application.StartupPath + "\\data";
Directory.CreateDirectory(path1);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\\realmlist.wtf", true);

string path2 = Application.StartupPath + "\\data\\zhTW";
Directory.CreateDirectory(path2);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\zhTW\\realmlist.wtf", true);




MessageBox.Show("DONE!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}

回答3:

提示没有找到路径,说明目录不存在,创建需要的文件夹就好了。

下面的写法更好一些。
using (StreamWriter fs = new StreamWriter(Application.StartupPath + @"\Output.w"))
{
fs.WriteLine("set realmlist tw.logon.worldofwarcraft.com");
fs.Flush();
}

File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\realmlist.wtf", true);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\realmlist.wtf", true);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\zhTW\realmlist.wtf", true);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\enTW\realmlist.wtf", true);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\zhCN\realmlist.wtf", true);
File.Copy(Application.StartupPath + @"\Output.w", Application.StartupPath + @"\data\enCN\realmlist.wtf", true);

回答4:

这是winform潜规则,在formload事件中你就是不能让程序直接去找文件夹路径,因为找路径那个函数还没初始化,但是你可以找文件路径。

回答5:

加上using试试
using(StreamWriter fs = new StreamWriter(Application.StartupPath + @"\Output.w"))
{
fs.WriteLine("set realmlist tw.logon.worldofwarcraft.com");
fs.Flush();
}