How can I replace multiple files while keeping their original names?

0
7
Asked By CuriousCoder42 On

I'm looking for a way to replace several files in a folder with the contents of a single external file, while retaining each file's original name. For example, I have a folder with files like test1.txt, test2.txt, etc. (let's say I have about 800 files), and I want to replace each of them with a different file called external.txt. I want the end result to be that test1.txt, test2.txt, etc. will all simply contain the new data from external.txt, but keep their original names. Is there a solution for this without having to manually copy and rename each file?

3 Answers

Answered By TechSavvy123 On

You can use PowerShell to achieve this! Just run a script like the one below, replacing the placeholders with your actual file paths:

```powershell
Get-ChildItem "{destination fullpath}" -Filter *.txt | ForEach-Object {
Copy-Item "{source full path}" -Force -Destination $_.FullName
}
```

This will copy the contents of your external file to each file in the specified folder. Just be sure to replace `*.txt` if you're dealing with different file types. It should work like a charm!

Answered By FeedbackGeek On

Just a heads up, I tried using PowerToys for this, but I wasn't sure if it did exactly what I needed or if I was using it wrong. So if you go that route, double-check the features!

Answered By HelpfulAmy On

Could you specify if you're on a Mac or a PC? It might change the solution a bit. If you're on a PC, definitely try the PowerShell method mentioned. If you’re on a Mac, let me know, and I can suggest something else!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.