Solved Replace all files in directory with copy of single file

MarkC0

New member
Member
VIP
Local time
9:21 AM
Messages
153
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 Computer My Computer

At a glance

Windows 7 Ultimate x64i7-2600k8GB 1600MHZZotac NVIDIA GTX 580 1.5GB
OS
Windows 7 Ultimate x64
CPU
i7-2600k
Motherboard
ASUS P8Z68 V-PRO
Memory
8GB 1600MHZ
Graphics Card(s)
Zotac NVIDIA GTX 580 1.5GB
Hard Drives
Intel 510 120GB SSD
Samsung Spinpoint HE103SJ HDD
PSU
NZXT HALE90 1000W PSU
Case
HAF-922
Cooling
Hyper 212
May I ask why?

That is exactly what many infections do :-(
 

My Computer My Computer

At a glance

W7 Pro SP1 64biti78GBIntel HD Graphics
Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
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 Computer My Computer

At a glance

Windows 7 Ultimate x64i7-2600k8GB 1600MHZZotac NVIDIA GTX 580 1.5GB
OS
Windows 7 Ultimate x64
CPU
i7-2600k
Motherboard
ASUS P8Z68 V-PRO
Memory
8GB 1600MHZ
Graphics Card(s)
Zotac NVIDIA GTX 580 1.5GB
Hard Drives
Intel 510 120GB SSD
Samsung Spinpoint HE103SJ HDD
PSU
NZXT HALE90 1000W PSU
Case
HAF-922
Cooling
Hyper 212
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 Computer My Computer

At a glance

Windows 10 Pro (x64)Intel Core i7-3930K (3.2GHz - 4.5GHz)4x Samsung 4GB PC3-12800 DDR3 (16GB 1600MHz)Nvidia Geforce GTX 690
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Alienware Aurora ALX R4
OS
Windows 10 Pro (x64)
CPU
Intel Core i7-3930K (3.2GHz - 4.5GHz)
Motherboard
Alienware Aurora-R4 x79
Memory
4x Samsung 4GB PC3-12800 DDR3 (16GB 1600MHz)
Graphics Card(s)
Nvidia Geforce GTX 690
Sound Card
SteelSeries Siberia Elite
Monitor(s) Displays
Dell UltraSharp U3011
Screen Resolution
2560x1600
Hard Drives
Samsung 850 Pro 256 GB, Seagate 1TB Desktop Hybrid HDD, 2x Western Digital 4TB Green HDD
PSU
875W Some Dell PSU <.<
Case
Alienware Aurora ALX
Cooling
Custom Liquid Cooling (EK CPU & GPU blocks) dual EK 480RAD
Keyboard
Logitech G710+ Mechanical
Mouse
Logitech G700s
Internet Speed
Verizon Fios (50 mbps average)
Other Info
Server: Intel NUC D54250WYK: i5-4250U, 16GB, 256 GB mSATA, Windows Server 2012 R2
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 Computer My Computer

At a glance

W7 Pro SP1 64biti78GBIntel HD Graphics
Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
Hard links might work - as long as users are not allowed to change their settings after the OP does the mass change.
 

My Computer My Computer

At a glance

W7 Pro SP1 64biti78GBIntel HD Graphics
Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
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 Computer My Computer

At a glance

Windows 7 Ultimate x64i7-2600k8GB 1600MHZZotac NVIDIA GTX 580 1.5GB
OS
Windows 7 Ultimate x64
CPU
i7-2600k
Motherboard
ASUS P8Z68 V-PRO
Memory
8GB 1600MHZ
Graphics Card(s)
Zotac NVIDIA GTX 580 1.5GB
Hard Drives
Intel 510 120GB SSD
Samsung Spinpoint HE103SJ HDD
PSU
NZXT HALE90 1000W PSU
Case
HAF-922
Cooling
Hyper 212
...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).
 
Last edited:

My Computer My Computer

At a glance

W7 Pro SP1 64biti78GBIntel HD Graphics
Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
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 Computer My Computer

At a glance

Windows 10 Home 64 bit
Computer type
PC/Desktop
OS
Windows 10 Home 64 bit
Back
Top