如何使用 cmd 删除 windows 中的中间目录?

How to delete an intermediate directory in windows using cmd?

例如:

directory1/
   101/online/img1.png
   102/online/img2.png
   103/online/img3.png

为此:

 directory1/
   101/img1.png
   102/img2.png
   103/img3.png

在此示例中,101(以及 102103...)目录仅包含一个目录 online,该目录始终同名.但是,online目录里面可能包含多个文件,但没有目录。

我正在寻找一种自动化的方式来像那样操作我的文件,因为我有很多这样的案例。我正在寻找 Windows 命令提示符或 Powershell 解决方案。

新答案和更新

这来自命令行:

pushd directory1
for /D %D in (*) do move /Y %D\online\*.* %D && rmdir /s /q %D\online
popd

或者来自 cmd 文件的这个:

pushd directory1
for /D %%D in (*) do move /Y %%D\online\*.* %%D && rmdir /s /q %%D\online
popd