1

So,

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

  • another duplicate: How to get all image files on windows 10? – phuclv Sep 8 '18 at 14:18
  • @phuclv - Your links highlight the important point of what to do with duplicate names in different folders. Also, the question implies that C: will be included in the search, and without additional scripting the JPGs in target folder will be found. I'd be inclined first to create a list of the files (xcopy /l?), which can be examined: Using an advanced editor (such as notepad++) the file list can be edited into copy commands; any files in the target folder can be removed, and duplicate names handled. All this could be handled on the fly in a batch file, but it would be rather complex. – AFH Sep 8 '18 at 15:18
1

The StackOverflow post Windows batch file to copy and keep duplicates has in this answer a prposed .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
)

Not the answer you're looking for? Browse other questions tagged or ask your own question.