Created
April 28, 2023 13:28
-
-
Save LiF-Lee/c1489374a56d6b2eff79c0bdb2d26f00 to your computer and use it in GitHub Desktop.
Copy files with batch script.
This file contains 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 | |
echo. | |
echo ***************************** | |
echo * * | |
echo * Github@LiF-Lee * | |
echo * * | |
echo ***************************** | |
:begin | |
:inputSrc | |
echo. | |
echo ^[!^] Please enter the source folder path: | |
set /p src= | |
if not exist "%src%\" ( | |
echo Invalid path. Please try again. | |
goto inputSrc | |
) | |
:inputDest | |
echo. | |
echo ^[!^] Please enter the destination folder path: | |
set /p dest= | |
if not exist "%dest%\" ( | |
echo Invalid path. Please try again. | |
goto inputDest | |
) | |
echo. | |
echo ^[!^] Please enter the name of the new folder: | |
set /p newFolderName= | |
echo. | |
echo ^[!^] Please enter the file extensions you want to copy, separated by commas (e.g., .txt,.pdf), or leave it empty for all files: | |
set /p fileExtensions= | |
echo. | |
echo ^[!^] Copying files, please wait... | |
echo. | |
setlocal enabledelayedexpansion | |
if not defined fileExtensions ( | |
for /r "%src%" %%f in (*) do ( | |
set "relPath=%%~dpf" | |
set "relPath=!relPath:%src%=!" | |
echo Copying: !relPath!%%~nxf | |
xcopy "%%f" "%dest%\%newFolderName%" /Q /Y /I | |
) | |
) else ( | |
set "fileExtensions=%fileExtensions: =%" | |
for %%a in (%fileExtensions%) do ( | |
for /r "%src%" %%f in (*%%a) do ( | |
set "relPath=%%~dpf" | |
set "relPath=!relPath:%src%=!" | |
echo Copying: !relPath!%%~nxf | |
xcopy "%%f" "%dest%\%newFolderName%" /Q /Y /I | |
) | |
) | |
) | |
endlocal | |
echo. | |
echo ^[!^] File copy operation completed! | |
echo. | |
echo ^[!^] Do you want to copy more files? (Y/N) | |
set /p restart= | |
if /i "%restart%"=="Y" goto begin | |
if /i "%restart%"=="y" goto begin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment