❬ Back to Blog
Duplicate file with different name [Python]
Want a file duplicated several times but with different filenames? Stop doing it manually, use python and give the work someone else.
Hi folks,
I recently came across a little issue. I had a file (an archive called americandlc.rpf
) that I had to duplicate several times but with different names.
The file was used by a game for displaying text in several languages in-game. However the text inside the file was generic and didn't require seperate archives for that.
So here was the tricky part: Either I copied the file manually 12 times and renamed it or do it automated.
Since I like efficiency I took the second step and wrote a simple python script that does the job:
Remember, the source_file was americandlc.rpf
. That means my code I was running on the command line looked like this:
Let's break that down:
-s
Is the parameter that takes the full path of the source file you will be copying from.
-l
Is a list parameter. You can specify there as many items as you want. The script will create these files then sourced from file above.
The script will place the files in the same directory as the source. Also note that if a file exists with the same name you have set as parameter then it will be overwritten.
As I said the script is very basic but does the job. You require python to use this. I'm sure it will work on windows too, but I haven't tested this.
Regards,
Alex