New
#1
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
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
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.
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:
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....Code:mklink /h [link-file] [source-file]
Added benefit to using hardlinks, the space used will only be consumed by one file instead of 15.
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
Hard links might work - as long as users are not allowed to change their settings after the OP does the mass change.
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.
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.
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).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")
Last edited by UsernameIssues; 25 Jun 2015 at 18:13.
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)