簡體   English   中英

FileNotFoundException嘗試將文件從一個目錄復制到另一個目錄時

[英]FileNotFoundException While trying to copy the file from one directory to another

我在“ C:\\ ABC \\ Temp”中有一些文件(.txt,word,excel文件),並且我想將所有.txt文件都移到“ C:\\ ABC \\ Text”中,但是我得到了FileNotFoundException

請找到隨附的代碼。

static void Main()
{
    string sp = @"C:/ABC/Temp";
    string dp = @"C:/ABC/TextFiles";
    string[] fileList=Directory.GetFiles(sp);

    foreach(string file in fileList)
    {
        if (file.EndsWith(".txt"))
        { 
            File.Move(sp,dp);
        }
    }
}
}

}

您正在嘗試使用File.Move移動整個目錄。

您還必須指定文件名:

File.Move(file, Path.Combine(dp, Path.GetFileName(file)));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM