[英]Subprocess call find -exec doesn't execute
I try to delete all folders including contents through a Python subprocess call using find and rm.我尝试使用 find 和 rm 通过 Python 子进程调用删除所有文件夹,包括内容。
The folder to be deleted is /root/subfolder/folder20200802
.要删除的文件夹是
/root/subfolder/folder20200802
。
In shell terminal, root dir, the command works:在 shell 终端,根目录中,命令有效:
find . -name 'folder2*' -type d -exec rm -rf {} \;
My script, saved in root dir, gives no error but it didn't delete the folder either:我的脚本保存在根目录中,没有出错,但也没有删除文件夹:
from subprocess import call
import os
call(['find', '.', '-name', '\'folder2*\'', '-type', 'd', '-exec', 'rm', '-rf', '{}', ';'])
By writing the output to a file, I was able to debug:通过将 output 写入文件,我能够调试:
from subprocess import call
import os
call(['find', '.', '-name', 'folder2*', '-type', 'd', '-exec', 'rm', '-rf', '{}', ' ', ';'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.