I want to move all JPG files on the entire drive (Including other users) to a folder on the desktop.
What's the command in CMD?
The folder I want to move the files to is C:\Users\stefa_000\Desktop\Allt
The StackOverflow post
Windows batch file to copy and keep duplicates
.bat script having two arguments: SourcePath TargetPath.
It recursively copies all files from SourcePath and its subfolders to TargetPath,
ignoring files from the target folder,
while appending an increasing counter to the base name for duplicates.
::copyFlat sourcePath TargetPath @echo off setlocal disableDelayedExpansion :: Initialize and validate arguments if "%~2" equ "" echo Error: Insufficient arguments>&2&exit /b 1 set "source=%~f1" if not exist "%source%\" echo Error: Source folder "%source%" does not exist>&2&exit /b 1 set "target=%~f2" if exist "%target%\" echo Error: Target folder "%target%" already exists>&2&exit /b 1 :: Do the work md "%target%" set /a n=0 for /r "%source%" %%F in (*) do if "%%~dpF" neq "%target%\" ( if exist "%target%\%%~nxF" ( set /a n+=1 set "full=%%F" set "name=%%~nF" set "ext=%%~xF" setlocal enableDelayedExpansion copy "!full!" "!target!\!name!_!n!!ext!" >nul endlocal ) else copy "%%F" "%target%" >nul )