I'm trying to figure out how to duplicate a single file for example: I have a file in "C:\ ..." and would like to duplicate this exact same file once. If also possible is there a way to use python to open specific documents?
thanks
I'm trying to figure out how to duplicate a single file for example: I have a file in "C:\ ..." and would like to duplicate this exact same file once. If also possible is there a way to use python to open specific documents?
thanks
Using a module named shutil, the function copy2 can be called with the path of the source file and the corresponding destination directory you want to write to. For example,
import shutil
shutil.copy2('/src/test.txt','/dst/test_copy.txt')
you can copy a file via the command line on windows: open cmd.exe then type cd "C:\ ..."
then type copy yourfile destination
. more info here
you can make python do this for you: you will need the subprocess module which comes integrated into python so you dont have to donwload anything.
like this:
import subprocess
subprocess.run('copy yourfile destionation')
remember that for this to work your python script should be in the same folder as "yourfile", why? because i type "yourfile" as a relative path relative vs absolute path
subprocess works for python 3.3 and newer versions so another way to do it would be:
import os
os.system('copy youfile destionation')
to open specific documents with python take a quick look at here: https://www.pythonforbeginners.com/files/reading-and-writing-files-in-python