ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

replace files in batch

(1/1)

kalos:
hello!

I have a directory, where there are many files with the same filename, inside various subdirectories

I want to replace each of these files, with a specific file I have

how can I do this at once? any solution?

thanks!

skwire:
This is easy to do but there is one caveat.  Do you want to replace the "contents" of these filenames with your specific file or do you want to replace the entire file with a new file.  For example:

Assume the files that need replacing are named File.txt.  Assume the file you want to use as a replacement is named NewFile.txt.

1) Did you want to replace the contents of File.txt with the contents of NewFile.txt (thus leaving the original File.txt name in place)?

2) Or, did you want to completely replace File.txt with NewFile.txt.

Of course, this scenario is moot if you're looking to replace File.txt with a completely different file that is also named File.txt.

kalos:
the 2)

I want to  replace the whole files File.txt with NewFile.txt

but the source file (the file that will replace the others) is named File.txt as well

skwire:
Here's an AuotHotkey snippet that should do it (adjust variables as necessary).  However, run it on a test folder structure first.


--- Code: Autohotkey ---myDir := "c:\tmp6"                 ; Will be recursed.myFileName := "File.txt"           ; Filename to look for.  Name only, no path.myReplacementFile := "c:\File.txt" ; Full path to replacement file. Loop, % myDir . "\*.*", 0, 1{    If ( A_LoopFileName = myFileName )    {        FileCopy, % myReplacementFile, % A_LoopFileFullPath, 1    } }

kalos:
it does the job, thanks!

Navigation

[0] Message Index

Go to full version