【问题标题】:C# changing the name of a JPEG image [duplicate]C#更改JPEG图像的名称[重复]
【发布时间】:2014-08-14 00:08:44
【问题描述】:

我正在尝试重新命名我的一堆 JPG,但我尝试的方法不起作用,我不知道还能尝试什么。

该程序适用于文件夹和 .txt,但不适用于我的 .JPG 图片,还有其他重命名解决方案,但不适用于 .JPG。有谁知道我可以改变什么?

我也尝试过File.Move,但它们都返回相同的错误消息, File not found exception was unhandled. Could not find file(我确定我的路径是正确的)

private void startRenaming_Click(object sender, EventArgs e)
{

    string old_name = @"C:\Users\u587945\Desktop\Vial_Suction_Test\Postion_1\Cycle_1.JPG",
           new_name = @"C:\Users\u587945\Desktop\Vial_Suction_Test\Postion_1\Cycle_1_Vial_1.JPG";

    bool exists = System.IO.Directory.Exists(old_name);
    if (exists)
    {
        MessageBox.Show("Found Directory!!!");
        System.IO.Directory.Move(old_name, new_name);
    }
    else
    {
        MessageBox.Show("Directory not found");
    }
}

【问题讨论】:

  • 为什么不使用 File.Exists 和 File.Move?
  • 为什么这不起作用?它做什么?
  • 根据标题标记为重复。您的示例代码使用 Directory API,因此重复项实际上可能与您想要做的事情无关 - 请随时编辑标题/帖子以明确您遇到的确切问题以及您想要实现的目标。

标签: c# jpeg renaming


【解决方案1】:

使用System.IO.File.Move,而不是目录 检查Rename a file in C#

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2013-04-18
    • 2020-02-26
    • 1970-01-01
    • 2018-10-05
    相关资源
    最近更新 更多