复制文件代码?

时间:2017-05-12 07:00:39

标签: c#

我需要将文件夹上的副本文件发送到另一个文件夹,我正在使用此

  string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
            foreach (string file in files)
            {
                folderBrowserDialog1.ShowDialog();
                string xx = folderBrowserDialog1.SelectedPath;
                folderBrowserDialog1.ShowDialog();
                string yy = folderBrowserDialog1.SelectedPath;
                File.Copy(xx, yy);

但是没有用。 为什么呢?

2 个答案:

答案 0 :(得分:0)

试试这段代码。

我假设您要读取文件然后将其写入新文件。

希望它有所帮助。

string sourceFile;
string newFile = "C:\NewFile\NewFile.txt";
string fileToRead = "C:\ReadFile\ReadFile.txt";
bool overwriteExistingFile = true; //change to false if you want no to overwrite the existing file.

bool isReadSuccess = getDataFromFile(fileToRead, ref sourceFile); 

if (isReadSuccess)
{
    File.Copy(sourceFile, newFile, overwriteExistingFile);
}
else
{
    Console.WriteLine("An error occured :" + sourceFile);
}



//Reader Method you can use this or modify it depending on your needs.
public static bool getDataFromFile(string FileToRead, ref string readMessage)
{
    try
    {
        readMessage = "";
        if (!File.Exists(FileToRead))
        {
            readMessage = "File not found: " + FileToRead;
            return false;
        }
        using (StreamReader r = new StreamReader(FileToRead))
        {
            readMessage = r.ReadToEnd();
        }
        return true;
    }
    catch (Exception ex)
    {
        readMessage = ex.Message;
        return false;
    }
}

答案 1 :(得分:0)

*.**.nic.phy80211p.sensitivity = -89dBm
*.**.nic.phy80211p.maxTXPower = 10mW
*.**.nic.phy80211p.thermalNoise = -110dBm