My code should move all files from \"old\" folders out into the parent as long as there are no files existing in the parent folder yet.
└───Folder
├───1
There are two problems in your attempt:
VAR
as you are writing and reading it in the same block of code; if you change it to set "VAR=true"
and set "VAR="
(empty), you could use if defined VAR
, which does not require delayed expansion;for
loop, so this is skipped in case there are already files;Here is a possible solution:
rem // Iterate over the changing directories:
for /D %%D in ("C:\testen\qft\*") do (
rem // Check whether current directory contains files:
dir /A:-D "%%~D\*.*" > nul 2>&1 || (
rem // Iterate over the files to process:
for %%F in ("%%~D\old\*.*") do (
rem // Actually move the files one level up:
move /Y "%%~F" "%%~dpF.."
)
)
)