FOR EACH 结合 FILE.MOVE

FOR EACH combined with FILE.MOVE

我想创建一个简单的程序,可以访问文件夹中的所有文件,所有这些文件都是同一类型的文件,然后使用 for each 重命名所有文件。 新名称将是 IMG###,其中 ### 是递增的。我知道该怎么做。如何引用要在 for each 中使用的所有图像?

示例:

For Each X in Folder {
    rename stuff here for x
 }

我只需要知道如何在x的地方引用文件。

你可以按照这样的思路去做:

var files = Directory.GetFiles(path, "*.", SearchOption.AllDirectories);

foreach (string item in files)
{
    //You can rename by moving the files into their 'new names'. 
    //The names are full paths
    File.Move(oldName, newName);
}