import os
import shutil
def listdirectory():
global computername
computername = input("What is the computer name? ")
completepathlist = fr"\\{computername}\C$\Users"
return os.listdir(completepathlist)
def username():
global completepath
global usernameinput
usernameinput = input("What is the user name? ")
completepath = fr"\\{computername}\C$\Users\{username}\AppData\Local\Google"
def programrunningcheck():
password = input("What is your password? ")
command = "taskkill /s " + str(computername) + " /u " + str(usernameinput) + " /p " +password+ " /im chrome.exe"
print(command)
os.system(command)
def deletegoogleapp():
shutil.rmtree(completepath)
#Functions being called
print(listdirectory())
username()
programrunningcheck()
deletegoogleapp()
Все работает до deletegoogleapp
функции deletegoogleapp
и получения
Имя пользователя функции\\DESKTOP-62A8SSM\C $\Users\" в 0x010C8B28\AppData\Local\Google
похоже, что переменная completepath
не передается из другой функции в функцию googleapp
.
изменить имя пользователя вашей функции:
global completepath
global usernameinput
def username(self):
usernameinput = input("What is the user name? ")
completepath = fr"\\{computername}\C$\Users\{username}\AppData\Local\Google"
Исправлена оригинальная проблема с var и внесены другие изменения в кодировку
import os
import shutil
import time
def listdirectory():
global computername
computername = input("What is the computer name? ")
completepathlist = fr"\\{computername}\C$\Users"
return os.listdir(completepathlist)
def username():
global completepath
usernameinput = input("What is the user name? ")
completepath = fr"\\{computername}\C$\Users\{usernameinput}\AppData\Local\Google"
def programrunningcheck():
print("We need your credentials to kill chrome")
techuser = input("What is your username? ")
techpassword = input("What is your password? ")
command = "taskkill /s " + str(computername) + " /u " + str(techuser) + " /p " +(techpassword)+ " /im chrome.exe"
time.sleep(5)
print(command)
os.system(command)
def deletegoogleapp():
shutil.rmtree(completepath)
#Functions being called
print(listdirectory())
username()
programrunningcheck()
deletegoogleapp()
Вам нужно сохранить возвращаемое значение имени username
, прямо сейчас, вы ничего не deletegoogleapp
чтобы deletegoogleapp
. Так что вы можете сделать:
u <- username()
programrunningcheck()
deletegoogleapp(u)
Это должно срабатывать, путь u
вернулся действителен.