-1

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.

Kevin
  • 708
  • 2
  • 9
  • 20
  • You want to delete all files in a directory and move an image (presumably from a thumb drive, or at least an other directory) to a specified directory? – unclemeat Feb 24 '14 at 23:45
  • Similar to that, but keep all the old files' names and put the same image in place of each of them with the same name, so if I had 'asdf.txt' and 'abc.doc' in a directory, the folder would end up as 'asdf.png' and 'abc.png' with the same image for each of them. – Kevin Feb 24 '14 at 23:52
  • So you have images with .txt and .doc extensions? Or you want to replace the files with a random image, and keep the same name? – unclemeat Feb 24 '14 at 23:55
  • Closer to the latter: I want to replace these files with a (not really random) image. Not just txt and doc files, but all of them in a directory. – Kevin Feb 25 '14 at 00:03
  • So it's just some troll code? – unclemeat Feb 25 '14 at 00:09
  • I guess you could use it that way, but I wanted to change a folder full of preexisting files all into the same picture. – Kevin Feb 25 '14 at 00:36

1 Answers1

0
@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.

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • How could I make it also add subfolders? As in keep the folder, but change everything inside it? It works, though, so thanks! – Kevin Feb 25 '14 at 18:34
  • @Kevin, change the inner for loop to `... for /r "%targetFolder%" %%f in (*) do ( ...` – MC ND Feb 25 '14 at 18:54