Skip to content

Instantly share code, notes, and snippets.

@PhoenixVX
Created July 20, 2024 02:53
Show Gist options
  • Save PhoenixVX/f4227a4e1536530112262505c08ddf3d to your computer and use it in GitHub Desktop.
Save PhoenixVX/f4227a4e1536530112262505c08ddf3d to your computer and use it in GitHub Desktop.
@echo off
setlocal
REM Check if correct number of arguments is provided
if "%~2"=="" (
echo Usage: %0 source_directory destination_directory
exit /b 1
)
set "source=%~1"
set "destination=%~2"
REM Ensure the destination directory exists
if not exist "%destination%" (
mkdir "%destination%"
)
REM Call the recursive copy function
call :recursiveCopy "%source%" "%destination%"
echo Copy complete.
endlocal
exit /b 0
:recursiveCopy
set "currentSource=%~1"
set "currentDestination=%~2"
REM Create the destination directory if it does not exist
if not exist "%currentDestination%" (
mkdir "%currentDestination%"
)
REM Copy all files in the current directory
for %%F in ("%currentSource%\*") do (
if not "%%~aF"=="d" (
copy "%%F" "%currentDestination%"
)
)
REM Recursively copy subdirectories
for /D %%D in ("%currentSource%\*") do (
call :recursiveCopy "%%D" "%currentDestination%\%%~nxD"
)
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment