Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Replace all files in directory with copy of single file

22 Jun 2015   #1
MarkC0

Windows 7 Ultimate x64
 
 
Replace all files in directory with copy of single file

Hello,

I would like to batch replace all files in a directory with a copy of a single file. The file names need to stay the same. Suggestions?

Thanks


My System SpecsSystem Spec
.
22 Jun 2015   #2
UsernameIssues

W7 Pro SP1 64bit
 
 

May I ask why?

That is exactly what many infections do :-(
My System SpecsSystem Spec
23 Jun 2015   #3
MarkC0

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by UsernameIssues View Post
May I ask why?

That is exactly what many infections do :-(
Settings files for an application. I'm using an application that creates a separate settings file for each registered user. I have 15 registered users. When I change the settings in the application it only saves to the settings file of that specific user. What I want to do is to replace the other 14 settings files with the newly updated one.

I do it manually right now with copy-paste and rename but it gets rather tedious as I am constantly making changes.
My System SpecsSystem Spec
.

23 Jun 2015   #4
logicearth

Windows 10 Pro (x64)
 
 

Try this. When you are manually copying the setting file you want. What you should do instead is replace all the others with a hardlink to the settings file that you want. You can use the command:

Code:
mklink /h [link-file] [source-file]
That way, when the file changes it carries over to all the others because they are just alias of the original. Assuming of course the application doesn't do something silly like delete the file and write a new one each time it changes it....

Added benefit to using hardlinks, the space used will only be consumed by one file instead of 15.
My System SpecsSystem Spec
23 Jun 2015   #5
UsernameIssues

W7 Pro SP1 64bit
 
 

Thanks for the explanation. I do something similar when I update some settings for an app that I oversee, only I have several hundred files to be changed. I use a scripting language named AutoIt to automate that task.

If I were to do this using a batch file, it would not be very fancy or flexible.
(The following assumes that the other 14 file names do not change.)
I would always use the same user to update/change/save the settings file.

The batch file would look something like:
copy user1 user2 /y
copy user1 user3 /y
copy user1 user4 /y
~~~
copy user1 user14 /y
My System SpecsSystem Spec
23 Jun 2015   #6
UsernameIssues

W7 Pro SP1 64bit
 
 

Hard links might work - as long as users are not allowed to change their settings after the OP does the mass change.
My System SpecsSystem Spec
25 Jun 2015   #7
MarkC0

Windows 7 Ultimate x64
 
 

Thanks for the help so far. Sorry for the delayed response.

Unfortunately the files names do change over time so specifying the file names would take just as long as manually swapping the files each time. Basically I'd be looking for something where I select a file, a folder, and it automatically swaps the files in the selected folder with a duplicate of the selected file.
My System SpecsSystem Spec
25 Jun 2015   #8
UsernameIssues

W7 Pro SP1 64bit
 
 

Quote   Quote: Originally Posted by MarkC0 View Post
...looking for something where I select a file, a folder, and it automatically swaps the files in the selected folder with a duplicate of the selected file.
You can use AutoIt. You only need to install AutoIt from that link. Use the default selections during the installation. You don't need the full customized editor - unless you start creating your own scripts from scratch. You should test the code below using a copy of the settings files in a test folder.

Create a new text file somewhere. Copy/paste/save the code below into that text file. Change the file extension on that file from TXT to AU3. Right click on that file and select Edit Script from the context menu.

Here is the code that you will want to change:

$Initial_Folder = "C:\Temp\"
Change the folder to whatever you want it to be. That will be the folder that the File Open Dialog boxes starts in. You can always navigate to other folders - if desired.

$source = FileOpenDialog("Select the source file", $Initial_Folder, "Text files (*.txt)")
$destination = FileOpenDialog("Select all of the destination files", $Initial_Folder, "Text files (*.txt)", 4)
Change the filter to describe the settings files and to indicate the file extension.

Save the changes. [See the notes after the code box.]

Run the script by double clicking on the AU3 file. [Or from within SciTE.]

You do not need to compile the script.


When running:
Select the file to be copied (source file) via the first File Open Dialog box - then click on Open.

Select all of the files to be copied over (destination files) via the second File Open Dialog box - then click on Open.

It does not matter if you happen to select the source file when selecting the destination files. Ctrl + A might work for you to select the destination files. Click/drag should also work when selecting the destination files.

The script only halts if the file copy fails.

For 15 file copies, you should see the final message box in less than a second.

Code:
AutoItSetOption ("TrayIconDebug", 1)

$Initial_Folder = "C:\Temp\"

$source = FileOpenDialog("Select the source file", $Initial_Folder, "Text files (*.txt)")

$destination = FileOpenDialog("Select all of the destination files", $Initial_Folder, "Text files (*.txt)", 4)

$destination_Array = StringSplit($destination, "|")

For $i = 2 to $destination_Array[0]
    If FileCopy($source, $destination_Array[$i], 1) = 0 Then
        MsgBox(0, "error", "The file copy failed for " & $destination_Array[$i])
        Exit
    EndIf
Next

MsgBox(0, "", "Done")
Notes - the steps above should make use of the light version of the SciTE script editor that comes with the AutoIt install. After making edits to the script, you might want to select Tools from that editor's Menu Bar and then select SyntaxCheck Prod. Doing that should save any changes and check the code for errors. If there are no errors, the the script can be run from within the SciTE script editor via Tools > Go (or F5).
My System SpecsSystem Spec
29 Jul 2016   #9
mgood7123

Windows 10 Home 64 bit
 
 

I hv a similar problem exept I hv to replace all files with 2 files (2 separate extentions per file, probably the model and the model shaders and lighting and stuff like that, idk)
neo.dcn_11
neo.mlb_INW11
neo_blind.dcn_11
neo_blind.mlb_INW11
neo_casual.dcn_11
neo_casual.mlb_INW11
ect

with a file of my choice, for example, replace all of them with this:
actor file redp5_herbshop.dcn_11
redp5_herbshop.mlb_INW11
and I highlited al the files I need to replace n its 86 files (43 actor files, or 43 character model files)
My System SpecsSystem Spec
Reply

 Replace all files in directory with copy of single file




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Files won't delete in directory - can't rename the directory either
So i have 3 files i cannot delete after uninstalling a game. I also cannot rename the folder they are in without windows explorer not responding and i have to restart explorer. I did take ownership method but that froze up to. I went into safe mode, and tried it that way - also didn't delete, it...
General Discussion
Replace default .pst file with existing .pst file
I upgraded from Vista Business to Seven Home Premium. Used Office 2007 in Vista and using it in Seven. In Vista, my .pst file was C:\Outlook\MyOutlookFolder.pst. Added it to Outlook using Data File Management, but none of my calendar entries appeared (my inbox and all my other folders are OK). When...
Microsoft Office
Batch file or Exe to copy & rename directory and update files
I require a batch file or free utility that i can redistribute from my web site to other users, (gamers) that will copy the contents of a directory inside their game to a new location and re-name the directory at the same time. Something like this; Copy "Genesis\Vehicles\truck\diesel\4tonbaker"...
General Discussion
Replace files in multiple directory, from a single directory
I have a 10 files that have all been categorised into about 40 folders. These files have been damaged. I have a backup of all these files, but they are not categorised and sit in a single directory. Does anyone know of an easy technique to batch replace the damaged files with the originals? ...
General Discussion
How to replace a bad perfproc.dll file
I ran sfc /scannow and it said I had a bad perfproc.dll file and it could not be repaired. I downloaded a good copy of the perfproc .dll file from another win7 PC. When I tried to copy it back to my PC win 7 would not allow me to paste it in the system32 folder. The system said the file was ether...
Performance & Maintenance


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 05:03.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App