Question

I want to be able to replace all the files in a directory with an image, using batch. I know a bit about xcopy, copy, and move, but I don't know how I might be able to use them or other commands to pull this off. Is there any simple, straightforward way to do this?

EDIT: For example, in the directory there are files 'foo.txt' and 'bar.doc'. After the batch, this folder would be left with 'foo.png' and 'bar.png', and when I open them I get the same image.

Was it helpful?

Solution

@echo off
setlocal enableextensions disabledelayedexpansion

set "sourceImage=c:\somewhere\something.png"
set "targetFolder=c:\myFolder"

for %%a in ("%sourceImage%") do for %%f in ("%targetFolder%\*.*") do (
    del /f /q "%%~ff" >nul 2>nul
    copy /y "%sourceImage%" "%%~dpf%%~nf%%~xa" >nul 2>nul 
)

endlocal

Not tested. Adapt as needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top