I’m trying to create a self-replicating Python program. Currently, the code I have looks something like this:
from sys import argv
import os
script = argv
name = str(script[0])
try:
os.mkdir('testFolder')
except:
pass
os.system(r'copy ' + name + ' testFolder')
This returns the following error:
The syntax of the command is incorrect.
What’s the cause of this, and what would be correct syntax?
>Solution :
You are not passing the correct arguments to copy – namely Windows paths are \ separated – e.g. C:\Users\xxxx\Desktop\script.py while Python’s sys.argv[0] will give you / separated path – c:/Users/xxxx/Desktop/script.py