I've been reading a lot here lately on self replicating code. I wanted to try my hand at it.
It only copies itself in forward directories. I.E. "C:\Users\cd.." is not supported yet but will be later.
I wanted to post it here to see if anyone had ideas, tips, and help with code layout. I know my code has to be sloppy and could be improved.
import os, random, sys
cur = os.listdir(os.getcwd())
def ishere(dir):
for i in dir:
if i == "PySpawn.exe":
return False
else:
return True
def dirList(dir):
lis = []
for i in dir:
try:
if i.index("."):
continue
except ValueError: lis.append(i)
return lis
li = dirList(cur)
if ishere(cur) == True:
f = open("PySpawn.exe","rb")
f = f.read()
l = open("library.zip","rb")
l = l.read()
os.chdir(os.getcwd()+"\\"+li[random.randint(1,len(li)-1)])
x = open("PySpawn.exe","wb")
x.write(f)
lx = open("library.zip","wb")
lx.write(l)