由于某种原因,每当我使用os.rmdir或os.removedirs和os.makedirs或os.mkdir时它不起作用。我的代码是
import os
path = r"C:UsersUserDesktopTestNew Text Document.txt"
os.rmdir(path)
输出为
Traceback (most recent call last):
File "C:UsersUserDesktopPythonprojectsprojects in python filessecuritymain.py", line 5, in <module>
os.rmdir(path)
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\Users\User\Desktop\Test\New Text Document.txt'
我的电脑只有一个\
import os
path = r"C:UsersUserDesktopTestNew Text Document.txt"
os.remove(path)
使用操作系统删除(路径(
os.rmdir(路径(用于删除空目录而非文件