如何在 Windows 中搜索 'Startup' 文件夹并删除我不需要的文件?

How do I search the 'Startup' folder in Windows and delete files I don't want?

基本上,我想做的是制作一个程序,一旦 运行,就会将其自身的副本保存到 Windows 'Startup' 文件夹中。

但是我的朋友做了某种 'antivirus'(不是很好)来检查 'Startup' - 当 Windows 启动时 - 对于任何扩展名为 [=14 的文件=] 或 .pyw

我正在尝试制作我的程序的一部分来做同样的事情,只是它应该在有时间删除我的文件之前删除 his 文件。

我正在编辑的程序不是我原创的,因此我不太了解它,但我对 Python 有一定的了解。我已经在我认为应该去的地方试过了,但是我得到了一个错误:

for file in os.listdir("C:/Users/%s/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/"):
    if file.endswith(".pyw") or file.endswith(".py"):
        os.remove(file)

这是我在 'Startup' 文件夹中有文件 (Test.py) 时遇到的错误:

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'Test.py'

如有任何建议,我们将不胜感激。谢谢。

os.remove(file)更改为os.remove("C:/Users/%s/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/" + file