Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Mac OS在python中将文件从垃圾箱移动到文件夹_Python_Macos - Fatal编程技术网

使用Mac OS在python中将文件从垃圾箱移动到文件夹

使用Mac OS在python中将文件从垃圾箱移动到文件夹,python,macos,Python,Macos,上述代码不起作用。我正在尝试将文件从垃圾箱移动到Mac上python的文件夹中。我收到的错误消息是 trash = "~/.Trash" new_folder = [] for current_file in os.listdir(trash): new_folder.append(current_file) 扩展~是shell的一项功能。您不能像普通文件系统路径那样使用它。幸运的是,Python有一个功能可以帮助您: FileNotFoundError: [Errno 2] No s

上述代码不起作用。我正在尝试将文件从垃圾箱移动到Mac上python的文件夹中。我收到的错误消息是

trash = "~/.Trash"
new_folder = []
for current_file in os.listdir(trash):
    new_folder.append(current_file)

扩展
~
是shell的一项功能。您不能像普通文件系统路径那样使用它。幸运的是,Python有一个功能可以帮助您:

FileNotFoundError: [Errno 2] No such file or directory: '~/.Trash'
有关详细信息,请参阅

trash = os.path.expanduser('~/.Trash')