I've made a batch to move files starting with a specific name to new created folders but i can't find a solution to do the same with folders. I have folders RLW-1 RLW-2 RLW-3

and i want to move all the above folders to a new created folder named "RLW" using a batch file. I tried this but it doesn't work:

mkdir "C:/Users/%USERNAME%/Desktop/Photos/RLW"
move "C:/Users/%USERNAME%/Desktop/Photos/RLW*" "C:/Users/%USERNAME%/Desktop/Photos/RLW"

This only creates the "RLW" folder but doesn't move the others in it. (Windows 10)

  • cmduses \ not / in directory names.
    – DavidPostill
    Apr 24 '20 at 12:23
  • Tried with "\" but no change.
    – Sakis
    Apr 24 '20 at 12:31
  • You can't use * when moving folders. You can use it only for files. Apr 24 '20 at 12:36

The wildcard * will only move files not folders. You need to list all the folders starting with RLW- and then move them one by one.

move "C:\Users\%USERNAME%\Desktop\Photos\RLW*" "C:\Users\%USERNAME%\Desktop\Photos\RLW"

for /f "tokens=*" %%G in ('dir /b /s /a:d "C:\Users\%USERNAME%\Desktop\Photos\RLW-*"') do move %%G C:\Users\%USERNAME%\Desktop\Photos\RLW

  • This worked perfectly! I can't thank you enough Reddy!
    – Sakis
    Apr 24 '20 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.