Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The title kind of already explains it but I'll be a bit more specific here.

I'm looking to replace a .jpg file in multiple different folders with a different .jpg file, but I want to be able to keep the original file's name so that I don't have to rename every image to avoid breaking the file path, how would I go about doing this?

e.g.

  1. Paste the .jpg to 100 folders
  2. .jpg replaces all other .jpg files regardless of file name
  3. The pasted .jpg then renames itself to the original overwritten file's name

Edit: Forgot to mention, these folders are all children of a single parent, not scattered all over the drive.

share|improve this question
    
What have you tried so far? –  Tog Nov 16 '13 at 13:15
    
You will probably need to explain how the folders are laid out, e.g., are they all children of a single parent folder? Are they scattered all over a drive? –  Patrick S. Nov 16 '13 at 13:16
    
@PatrickS. Updated, thanks for telling me about that. –  Reality Nov 16 '13 at 13:42
    
@Tog Not much, I can paste the file into all the folders at the same time no problem, but it's just everything after that leaves me scratching my head. Sorry for my ignorance, I'm not very knowledgeable on this subject. –  Reality Nov 16 '13 at 13:45
add comment

1 Answer

up vote 3 down vote accepted

C:\newpic.jpgC:\newpic.jpgThis is what PowerShell is perfect for:

ls "C:\files" -Recurse -Filter "*.jpg" | ForEach{ cp "C:\newpic.jpg" $_.FullName -WhatIf }

the more verbose version is:

Get-ChildItem "C:\files" -Recurse -Filter "*.jpg" | ForEach-Object { Copy-Item "C:\newpic.jpg" -Destination $_.FullName -WhatIf }

The first part loops through all jpg files under C:\files including any sub-directories. The second part takes each of those files and overwrites it with your new file.

The commands above will actually only tell you what they would do without doing it, remove the -WhatIf to actually perform the copy operation.

share|improve this answer
    
Perfect, thanks! –  Reality Nov 16 '13 at 14:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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