Hey! The reason your command didn’t work is due to a few issues:
%nxF
is invalid — it should be %~nxF
to get the filename and extension.
rm
isn’t a valid command in Windows CMD — use del
instead.
Quoting %Dir2%\*
like "%Dir2%\*"
breaks the wildcard — CMD won't expand it properly.
You're using variables like %Dir1%
inside the for
loop, but CMD may not expand them correctly there.
Here’s a working version for CMD (replace <username>
and <folder>
):
for %F in (E:\*) do @if exist "D:\Users\<username>\<folder>\%~nxF" del "E:\%~nxF"
and if you want to test first:
for %F in (E:\*) do @if exist "D:\Users\<username>\<folder>\%~nxF" echo del "E:\%~nxF"
Let me know if you're running it from a batch file — the syntax changes slightly!