How do I go about running a batch script from the top level folder, which will find all .bak files in each subfolder and then move those .bak files into a "backup" subfolder inside each of those folders? (The "backup" subfolder may or may not already exist)
For example:
toplevel\subfolder1\filename.bak
toplevel\subfolder2\anotherfile.bak
should become:
toplevel\subfolder1\backup\filename.bak
toplevel\subfolder2\backup\anotherfile.bak
I've been using this script to copy files recursively into subfolders, but when I change 'copy' to 'move' I get "The syntax of the command is incorrect"
Code: Select all
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ( ' dir "*.bak" /b /s /a-d ' ) do (
echo processing "%%a"
set "name=%%~nxa"
pushd "%%~dpa"
copy /b /y "%%a" ".\backup\!name:~0!"
popd
)
Not quite sure how to proceed here...