Created
July 20, 2024 02:53
-
-
Save PhoenixVX/f4227a4e1536530112262505c08ddf3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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